Core Concept of Applying External CSS in HTML
When you add the CSS rules for any page elements into a dedicated file with a.css extension, that approach is known as external CSS. This file can be used for one page or more than one page.
In this code:
- External CSS file is connected with <link rel=”stylesheet” type =”text/css” href=”ext.css”>.
- In the external CSS file, the background color for the body tag and the text color as maroon with right margin to the H1 tag are applied.
Why is it used?
This is the standard and professional approach. When you need to apply consistency to the whole website and don’t want to repeat the code. This is the basic practice to add or apply styles to a page or the whole website.
Real-life Applications
- Multi-page websites: When there are two or more pages, then external CSS is used.
- Dark/Light mode switching: To apply different themes of a website, like light, dark, or any other theme. The dhimanp website is the best example of external CSS file embedding because this website contains the external CSS implementation for changing the theme styles.
- Consistency & Reusability: To maintain consistency and reusability, the external CSS is used.
Benefits of this Program
- Easy Maintenance: Because all the common CSS code is in a single file, it is easy to update or maintain.
- Clean HTML code: Due to a dedicated CSS file, the code will be neat and clean.
- Improves the page Load Speed: Due to a dedicated CSS file, the size of the HTML file will be reduced, so the page load speed will be improved, and SEO will also be improved.
