CSS style sheets are to be included in an HTML document to apply CSS rules on the HTML elements used for designing the website. There are different ways to use CSS in web pages to styles the pages. These are CSS External, Internal, and Embedded. Let’s discuss them one by one.
Inline Style Sheet
Inline Style Sheets are local in functionality and application with reference to an HTML element. The inline style sheet is included in a specific element (TAG) of an HTML page where you need to apply the style. The styling rules are defined in the STYLE attribute of an HTML element’s opening tag. All the CSS rules are placed in a double quotes as a value to the STYLE attribute. The CSS style rules are mentioned as property: value pairs separated by semi colons.
Syntax
< TAGNAME STYLE=”property: value; property: value;….”> </TAGNAME>
Example
<P STYLE="COLOR:PINK;FONT-STYLE:italic;">Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. </P>
Inline Style sheet is best to use when you want to apply specific style only once for an HTML element. If browser encounters all ways of CSS in an HTML page like External and Embedded, the inline Style sheet is preferred over them.
Embedded or Internal Style Sheet
Embedded Style Sheets are local in functionality and application within one HTML document. The Embedded style sheet is included in a specific HTML page in which you need to apply a consistent design at document level. The internal CSS styling rules are defined in the <HEAD></HEAD> enclosed in <STYLE></STYLE> element of an HTML page.
The CSS style rules are mentioned for the required selectors (HTML Tags, Classes or IDs) in form of property: value pairs separated by semi colons and enclosed in curly parenthesis after the name of the selector. The TYPE attribute of STYLE tag must be set with “text/css” to inform the browser to interpret the contents of <STYLE> tag as text applying CSS.
Syntax
<HEAD> <STYLE TYPE=”text/css”> SELECTOR{property: value; property: value;….} </STYLE> </HEAD>
Example
<HEAD><STYLE TYPE="text/css"> P{COLOR:PINK; FONT-STYLE:italic;} BODY{COLOR:#FFFFFF; BACKGROUND-COLOR:#000000; FONT-SIZE:14px;} H1{COLOR:red; FONT-SIZE:22px;FONT-STYLE:BOLD;} H2{COLOR:red; FONT-SIZE:14px;FONT-STYLE:BOLD;} </STYLE> </HEAD> <BODY> <H1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </H1>Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. <H2>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor.</H2> <P>Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel,</P> tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. <P>Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. </P> In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. <P>Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. </P>Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. </BODY>
Embedded or internal style sheet is best to use when you want to apply specific style to same HTML elements in one web page only. If browser encounters different ways of applying CSS in HTML page like External or Internal, then Internal Style sheet is preferred over External Style Sheet but not over Inline Style Sheet.
CSS External Style Sheet
External Style Sheet is global in functionality and application within a web application or website. The CSS External style sheet, as the name implies, is an external file ( a template) with .CSS extension storing all the CSS rules for every possible HTML element of the website or web application. It must be referred in any page of the website which you want to style with these style rules in the <LINK> HTML Tag.
The CSS external file does not contain any HTML markup elements with content. If you make any change in any rule in the External style sheet, the change will be reflected in all pages of the website which refer to this style sheet and the modified selector.
The CSS External style sheet rules are mentioned for the required selectors (HTML Tags, Classes or IDs) in form of property: value pairs separated by semi colons and enclosed in curly brackets after the selector. So, a style sheet is a collection of the CSS rules of definitions.
Syntax
<HEAD> < LINK REL="Stylesheet" TYPE="text/css" HREF="CSS external file URL"> </HEAD
Example
P{COLOR:YELLOW; FONT-STYLE:italic;} BODY{COLOR:#FFFFFF; BACKGROUND-COLOR:ff0000; FONT-SIZE:14px;} H1{COLOR:blue; FONT-SIZE:28px;FONT-STYLE:BOLD;} H2{COLOR:blue; FONT-SIZE:18px;FONT-STYLE:BOLD;}
<HEAD> <LINK REL="Stylesheet" TYPE="text/css" HREF="rules.css"> </HEAD> <BODY> <H1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </H1>Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. <H2>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor.</H2> <P>Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel,</P> tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. <P>Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. </P> In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. <P>Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. </P>Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. </BODY>
External style sheet is best to use when you want to apply consistent style to HTML elements in complete website. If browser encounters different ways of applying CSS in HTML page like External, Embedded or Internal, then External Style sheet is the least preferred over all the style sheets.