How to Use CSS in HTML
Similarly, writing attributes for each element make the entire code spaghetti. To avoid this we use CSS(Cascading Style Sheet), which helps in separating the style partly from the HTML part.
CSS with HTML
Let us consider the following code example where we apply various styles to an element.
A journey of a thousand miles begins with a single step
In this example we have used inline CSS, the problem is that whenever I need to create a similar element, I would have to rewrite all the styling parts with that element. The solution to this is to use internal CSS. Since we are now dealing with CSS, we will need to work with classes. Have a look at this example.
This is an example of how css can be used
In the example above, we have created a <style> tag and inside that style tag, we have created a class called .theitstuff. It is important to note, that all CSS class names are accessed by the. specifier. After that, in the body section, we just gave our element a class attribute with the class name that we created. Now all the style code written for that class will be given to the element. This is very useful when you have to make changes in multiple elements that are similar.
You can see that we have placed a
<link rel="stylesheet" type="text/css" href="filename.css">