i

Learn HTML and CSS in 10 Days

Referencing CSS

To make your CSS to share words with HTML you must reference your CSS file inside HTML. One of the best technique to reference CSS is by summing up all styles in one single external stylesheet and then referencing it within the

element present in the HTML file. If you are using a separate stylesheet, then you can utilize similar styles over a whole website and rapidly make changes sitewide.

To make a CSS stylesheet, open up a text editor and save it by the extension name as '.css'. Note that you should keep the CSS file in the same folder or subfolder containing your HTML file.

Inside the HTML file there is an element named as  Inside it is the element which helps in establishing the relationship between the HTML and the CSS file. As we are linking our HTML file with the CSS file, thus, we need to use the ‘rel' attribute provided with the value as a stylesheet. A second attribute, i.e. the 'href' attribute, helps in identifying the location where the CSS file is situated.

If you want your CSS to work properly, the path given for the href attribute value must straightforwardly associate to where our CSS record is kept. In the above code, the main.css file is present in the same location where the HTML file is situated (root directory).

If you have saved your CSS file in subfolder or subdirectory, then the href attribute value requires to correspond to this way in like manner. Take an example, like, if your CSS file main.css is kept inside a subfolder with the name of stylesheets, the value of href attribute should be stylesheets/main.css.

Now our web page is coming to life. We have not gone too deep inside CSS, but still, you will be noticing that a few styles have default styles we haven't proclaimed inside our CSS. Here the browser itself is imposing the default values. But don't worry, we can overwrite these styles as per our requirement, and we can do that using CSS resets.