Why use HTML and CSS? What’s the difference?
Here is how html and css work together .HTML and CSS are two different types of luxury( law), which have their unique syntax. There’s an important distinction between the two. You can suppose the HTML as the structure for the runner, while the CSS gives the HTML it’s styling. so know how html and css work together.

HTML = structure
CSS = style

By the way, HTML stands for HyperText Markup Language and CSS stands for Slinging Style.

For an amazing illustration of the conception of separating content from style with HTML and CSS, take a look at the point CSS Zen Garden.

This point was enough inspiring it was one of the first online exemplifications of just how important this relationship between HTML and CSS actually is. As you browse through the alternate designs for the point, bear in mind that every single design uses exactly the same HTML! The only thing that changes from design to design is the CSS train. This is a great illustration of what can be fulfilled using just CSS to change the look of a web runner.

In posterior tutorials when our law gets complex, we ’ll learn just how important it’s to keep the two separate. For now, let’s dig in and actually law.

Step 1


produce a new train called “style.css ” and save it in the same brochure as your train called “index.html ”.

Linking your HTML and CSS lines


Step 2


Before we indeed write the CSS, we actually have to go back to our HTML. We need to write a new line to link the html train and the css train together. So, open up theindex.html train from the former tutorial and add the stressed line of law below( line 5) to the section of your document. The result should look like this

<!DOCTYPE html>
<html>
 <head>
  <title>This is my page title.</title>
  <link href="style.css" rel="stylesheet" type="text/css" />
 </head>
 <body>
  <h1>This is a heading 1 element</h1>
  <p>Hello world, this is a simple paragraph.</p>
 </body>
<html>

This is my runner title.

This is a heading 1 element
Hello world, this is a simple paragraph.

This line of law links the new CSS train to your HTML train. Let’s break it down the href trait actually specifies the relative link to the css train. We ’ll get to links latterly, for now, just make sure thestyle.css train is in the same brochure as yourindex.html train. The rel trait tells the cybersurfer that this is a stylesheet. The type trait tells the cybersurfer that this linked train should be interpreted as CSS syntax.

Understanding CSS syntax

Also Read: How html forms work (hackanons.com)


Step 3


Now on to the real CSS. The first thing we ’re going to do is make the paragraph textbook a different color. So type or bury this into yourstyle.css train

p { color:blue; }


This looks different than the law in our HTML train because it’s a different syntax. I ’m going to add some whitespace and breaks to that law like this

p { 
  color:blue; 
}

Both of the below exemplifications are the exact same as far as your cybersurfer is concerned. But inventors generally write out CSS like the after illustration in order to visually separate the styles. This is helpful when your CSS lines start to accumulate hundreds of different styles, and for learning what the syntax means

ruleset

HTML For Beginners The Easy Way: Start Learning HTML & CSS Today »


The wholeness of the textbook over is technically called a rule set, or simply rule. Its broken up into a many different corridor

selector-declaration-block

chooser- protestation- block
In this particular rule set, we can call p a chooser.( This “ selects ” the part of the corresponding HTML will be effected — the p{} selects the in our HTML train.)

The law including and between the curled braces{} is called the protestation block.

declaration


There’s a single protestation inside of our protestation block colorblue;. Affirmations are name- value dyads( analogous to HTML attributes). Then, the name of the protestation is “ color ” and the value is “ blue ”. It’s important to separate the name and value with a colon and end the protestation with a semicolon;.

Step 4


We ’re going to add a new rule set to change the color of the title, like so

p { 
  color:blue; 
}
h1 {
  color:red;
}

Now our head 1 should be red and our paragraph should be blue, as seen below, and in the rally.

Screen Shot 2013-09-25 at 4.14.15 PM

So, save your CSS and also take a look at the corresponding HTML in your cybersurfer to make sure yours aesthetics like the below illustration.

Categorized in:

Tagged in:

,