Inline, Internal and External CSS Styling and Their Priority
Inline, Internal and External CSS Styling and Their Priority
PW SKILLS
Topic
● Introduction to link CSS to HTML
PW SKILLS
Introduction to link CSS to HTML
Linking CSS to HTML is a fundamental step in web development to control the presentation
and style of web pages.
PW SKILLS
Inline CSS styling with example and its priority
Inline style are one of the ways to add CSS to an HTML document. A style attribute can be
added to any HTML tag and CSS properties are added to it.
Note - Inline styles override any CSS Inline or External style sheet
Example
PW SKILLS
Internal CSS styling with example and its priority
An internal stylesheet is a method of adding CSS rules directly within the <style></style>
element in the <head> section of an HTML document
This allows developers to define styles for specific HTML elements of classes within the same
HTML file, without the need for an external stylesheet
Note - It has priority less than the inline styles and will be able to override external styles but
not the inline styles.
<!DOCTYPE html>
<html>
<head>
<title>Example of Semantic HTML Tags</title>
<style>
h1 {
color: green;
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
PW SKILLS
External CSS styling with example and its priority
An external stylesheet is a separate file that contains CSS rules and is linked to an HTML
document using the <link> element.
PW SKILLS
Pros and cons of Inline, Internal and External
CSS styling
CSS styling Pros Cons
● Provides complete control over the styling of a specific ● Can be difficult to maintain, especially on larger projects
element ● Increase page load times if used excessively
Inline
● Easier to override global styles for specific elements as it ● Not very scalable, as each individual element needs to
has the highest specificity. have its own inline style.
● More maintainable than inline CSS, as styles can be defined ● It can be difficult to apply styles consistently across
once in the head section of the HTML document and applied multiple pages, as style must be defined in each HTML
Internal to multiple elements. document individually
● It provides greater flexibility than inline CSS ● It can still lead to code duplication if the same styles are
● It is easier to override styles than inline CSS. defined in multiple sections of the same HTML document.
● It is the most maintainable option, as styles can be defined
● It may not be as flexible as inline or external CSS, as
in a single file and applied to multiple pages.
styles must be defined in a separate file and cannot be
● it is the most efficient option, as the CSS code can be
applied directly to an HTML element.
cached by the browser, reused across multiple files, and
● It requires an additional HTTP request, which can slow
External easily edited.
down the page load time.
● It allows for greater organisation and consistency, as styles
● it has lower specificity than inline and internal CSS, which
can be separated into different files and easily edited
means it can be overridden by other styles applied to the
● it is the most recommended approach for small to big
same element.
projects.
PW SKILLS
THANK YOU
PW SKILLS