Pub Pixel Avatar Image

HTML5 Snippets - Embed A CSS Style Sheet To Your Web Page That Will Always Be Applied To Your Web Page

Published:

Rate Article (Sign in and be the first to rate this article.)

Article Details

Views: 430

First Published:

Word Count: 581

Edition: 1

Now lets say that you want to add some CSS style rules directly to your web page. This is known as an embedded style sheet as well as an internal style sheet. And lets also say that you would like the embedded style sheet to always be applied to your web page alongside other active CSS style sheets that are also being applied to the very same web page. In-order to tell the browsers that you would like to always have your embedded style sheet applied to your web page, which is also known as a persistent style sheet. You will first have to embed the style sheet directly to your web page using the <style> element.

Now the <style> element when added to your web page will allow you to add one or more CSS style rules to that very same web page. The <style> element also requires an end tag </style>. You must place the CSS style rules between the <style> elements start tag <style> and end tag </style>.

It's important to remember that you will need to place the <style> element within the <head> element of the web page in-order for your <style> element to work properly.

Another important thing to remember is that embedded style sheets will override external style sheets.

Now let me first show you the code by itself for the HTML snippet for embedding a CSS style sheet to your web page that will always be applied to your web page using the <style> element. And then I will show you how to code and where to place the HTML snippet for both HTML5 and XHTML5.

Here is the HTML code snippet below to embed a CSS style sheet to your web page that will always be applied to your web page using the <style> element.


<style>Place your CSS style rules here</style>

Here is the HTML code snippet to embed a CSS style sheet to your web page that will always be applied to your web page using the <style> element for HTML5 in the example below.


<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Welcome To HTML5</title>
 <style>  
  body { background: #8a2be2; }
  p { font-size: 1.8em; color: #ffffff; }
 </style>
</head>
<body>

 <p>Your web page should now have an embedded style sheet that will always be applied to your web page.</p>  

</body>
</html>

And here is the HTML code snippet to embed a CSS style sheet to your web page that will always be applied to your web page using the <style> element for XHTML5 in the example below.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">  
<head>
 <meta charset="UTF-8" />
 <title>Welcome To XHTML5</title>
 <style>  
  body { background: #8a2be2; }
  p { font-size: 1.8em; color: #ffffff; }
 </style>
</head>
<body>

 <p>Your web page should now have an embedded style sheet that will always be applied to your web page.</p>  

</body>
</html>

Article Tags

Tag Article (Sign in if you want to tag this article.)

Share This Article

Send To Facebook Link

Tweet This Link

Send To LinkedIn Link

Send To StumbleUpon Link

Digg This Link

Send To Google Plus One Share Link

Send To Reddit Link

Send To Tumblr Link

Send To Delicious Link

Send To FriendFeed Link

Send To Diigo Link

Email Link

AddThis Link

0 Comments

Leave Comment (Sign in and be the first to comment on this article.)

Important

This site cannot guarantee the accuracy of articles, comments, answers and other types of content or media submitted by members or anonymous users and guests, and we recommend that you use common sense when following any advice or information found on this site. Read our full Content Disclaimer Agreement for further information.