![]() |
VOOZH | about |
CSS (Cascading Style Sheets) is essential for defining the presentation of web pages, including layout, colors, and fonts. There are three primary methods to apply CSS:
Here, we are going to discuss each of them in detail:
Inline CSS is a way of defining the styling of an HTML element by adding CSS rules directly to the element's tag using the "style" attribute. It is used for quick and simple styling changes to specific elements, without creating a separate CSS file.
<p style="css_styles"> // Content </p>
In this Example:
Internal CSS, also known as embedded CSS, involves adding CSS rules directly within the <style> element in the <head> section of an HTML document. It allows styling specific to that document.
<style>
// CSS Properties
</style>In this Example,
External CSS is used to place CSS code in a separate file and link to the HTML document. To use external CSS, create a separate file with the .css file extension that contains your CSS rules.
<head>
<link rel="stylesheet"
type="text/css" href="style.css">
</head>
File Name: index.html
Create a CSS file named styles.css and write all the codes in that CSS file
File name: style.css
In this Example,
| Feature | Inline CSS | Internal CSS | External CSS |
|---|---|---|---|
| Location | It is used within HTML tag using the style attribute. | It is used within <head> section of HTML document. | It is used in a separate .css file. |
| Selector Scope | Affects a single element or a group of elements. | Affects multiple elements within the same HTML element. | Affects multiple HTML documents or an entire website. |
| Reusability | Not reusable. Styles need to be repeated for each element. | Can be reused on multiple elements within the same HTML document. | Can be reused on multiple HTML documents or an entire website. |
| Priority | Highest priority. Overrides internal and external styles. | Medium priority. Overrides external styles but can be overridden by inline styles. | Lowest priority. Can be overridden by both inline and internal styles. |
| File Size | Inline styles increase the HTML file size, which can affect the page load time. | Internal styles are part of the HTML file, which increases the file size. | External styles are in a separate file, which reduces the HTML file size and can be cached for faster page loads. |
| Maintainability | Not easy to maintain. Changes need to be made manually to each element. | Relatively easy to maintain. Changes need to be made in one place in the <head> section. | Easiest to maintain. Changes need to be made in one place in the external .css file. |