what are inline internal and external CSS and when should you use each one CSS can be applied to a web page in three main ways inline internal or external each method has its own use case advantages and limitations and knowing when to use each one is essential for writing clean efficient and maintainable code let's break down the three types of CSS and when you should use them inline CSS is written directly within an HTML element using the style attribute it applies styles to a specific element here is an example using inline CSS in this example
we are using the style attribute to set the paragraph text to Red here is what the example looks like rendered on the page inline CSS is generally used for quick oneoff Styles or to override other styles for a specific element however it should be avoided in most cases because it can clutter the HTML and make the code harder to maintain most of the time it's better to use internal or external CSS internal CSS is written within the style TX inside the head section of an HTML document it applies styles to the entire page and is
useful when you need to style a single document here is an example of internal CSS in this example the internal CSS applies blue text to all P elements on the page you can see the result on the screen internal CSS is best used when you need to apply styles to a specific page rather than across multiple Pages it's useful for single page websites or when the Styles don't need to be reused elsewhere however there are some downsides such as not promoting reusability across multiple Pages additionally like inline CSS it mixes HTML and CSS making the
code harder to maintain in larger projects external CSS is written in a separate CSS file and linked to the HTML document using the link element in the head section it allows you to style multiple Pages consistently and is the preferred method in professional web development here is the HTML part of our code example in an earlier lecture video you learned that the link element has a real attribute that specifies the relationship between the current document and the linked resource on the other hand the hre attribute specifies the URL of the linked resource indicating where the
resource should be retrieved from here is the CSS of this example in a separate file named style.css this example targets all paragraph elements on the page and sets the text color to Green here is what the example looks like rendered on the page external CSS is ideal for large projects where you want to maintain a consistent style across multiple Pages it promotes separation of concerns by having HTML handle the structure and CSS handle the styling which makes the code more maintainable and scalable understanding when to use each type of CSS is crucial for efficient and
effective web development in most cases external CSS should be your go-to approach especially for larger and more complex projects