Essay Style Sheet Html

On By In 1

CSS How To...

❮ PreviousNext ❯


When a browser reads a style sheet, it will format the HTML document according to the information in the style sheet.


Three Ways to Insert CSS

There are three ways of inserting a style sheet:

  • External style sheet
  • Internal style sheet
  • Inline style

External Style Sheet

With an external style sheet, you can change the look of an entire website by changing just one file!

Each page must include a reference to the external style sheet file inside the <link> element. The <link> element goes inside the <head> section:

Example

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>

Try it Yourself »

An external style sheet can be written in any text editor. The file should not contain any html tags. The style sheet file must be saved with a .css extension.

Here is how the "mystyle.css" looks:

body {
    background-color: lightblue;
}

h1 {
    color: navy;
    margin-left: 20px;
}

Note: Do not add a space between the property value and the unit (such as ). The correct way is:



Internal Style Sheet

An internal style sheet may be used if one single page has a unique style.

Internal styles are defined within the <style> element, inside the <head> section of an HTML page:

Example

<head>
<style>
body {
    background-color: linen;
}

h1 {
    color: maroon;
    margin-left: 40px;
}
</style>
</head>

Try it Yourself »

Inline Styles

An inline style may be used to apply a unique style for a single element.

To use inline styles, add the style attribute to the relevant element. The style attribute can contain any CSS property.

The example below shows how to change the color and the left margin of a <h1> element:

Tip: An inline style loses many of the advantages of a style sheet (by mixing content with presentation). Use this method sparingly.


Multiple Style Sheets

If some properties have been defined for the same selector (element) in different style sheets, the value from the last read style sheet will be used. 

Example

Assume that an external style sheet has the following style for the <h1> element:

h1 {
    color: navy;
}

then, assume that an internal style sheet also has the following style for the <h1> element:

h1 {
    color: orange;   
}

If the internal style is defined after the link to the external style sheet, the <h1> elements will be "orange":

Example

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
h1 {
    color: orange;
}
</style>
</head>

Try it Yourself »

However, if the internal style is defined before the link to the external style sheet, the <h1> elements will be "navy":

Example

<head>
<style>
h1 {
    color: orange;
}
</style>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>

Try it Yourself »

Cascading Order

What style will be used when there is more than one style specified for an HTML element?

Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number one has the highest priority:

  1. Inline style (inside an HTML element)
  2. External and internal style sheets (in the head section)
  3. Browser default

So, an inline style (inside a specific HTML element) has the highest priority, which means that it will override a style defined inside the <head> tag, or in an external style sheet, or a browser default value.

Try it Yourself »


Test Yourself with Exercises!

Exercise 1 »  Exercise 2 »  Exercise 3 »  Exercise 4 »


❮ PreviousNext ❯

'); doc.close(); function init(b, config) { b.addVar({ 'abTests[0][testName]': 'cssJsInjectionInlineLinkColor', 'abTests[0][bucketValue]': 3, 'abTests[1][testName]': 'indexUniversalWrapper', 'abTests[1][bucketValue]': 0, 'abTests[2][testName]': 'videoRangeToPlay', 'abTests[2][bucketValue]': 1, 'abTests[3][testName]': 'videoControls', 'abTests[3][bucketValue]': 1, 'abTests[4][testName]': 'cssJsInjection', 'abTests[4][bucketValue]': 0, 'ptax': 'tho_web-design', 'tax0': 'tho', 'tax1': 'tho_sciences-math', 'tax2': 'tho_computer-science', 'tax3': 'tho_web-design', 'tax4': '', 'templateId': '65', 'templateName': 'flexTemplate', 'templateView': 'PERSONAL_COMPUTER', 'tmog': 'g1621270231869702d31302d31342d312d31322d311b61d', 'mint': 'g1621270231869702d31302d31342d312d31322d311b61d', 'idstamp': 'g1621270231869702d31302d31342d312d31322d311b61d', 'dataCenter': 'us-east-1', 'serverName': 'ip-10-14-1-12-1', 'serverVersion': '2.40.7', 'resourceVersion': '2.40.7', 'cc': 'UA', 'city': '', 'lat': '50.45', 'lon': '30.523', 'rg': '', 'clientTimestamp': new Date().getTime(), 'globeTimestamp': 1520727761688, 'referrer': document.referrer, 'sessionPc': '1', 'userAgent[familyName]': 'IE', 'userAgent[versionMajor]': '11', 'userAgent[versionMinor]': '0', 'userAgent[osName]': 'Windows 7', 'userAgent[osVersion]': '6.1', 'userAgent[mobile]': 'false', 'userAgent[raw]': 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko' }); b.init({ beacon_url: 'https://rd.about.com/boomerang/reference', user_ip: '178.159.37.71', site_domain: 'thoughtco.com', BW: { enable: false }, DFPTiming: {} }); } if (document.addEventListener) { document.addEventListener("onBoomerangLoaded", function(e) { // e.detail.BOOMR is a reference to the BOOMR global object init(e.detail.BOOMR); }); } else if (document.attachEvent) { // IE 6, 7, 8 we use onPropertyChange and look for propertyName === "onBoomerangLoaded" document.attachEvent("onpropertychange", function(e) { if (!e) e=event; if (e.propertyName === "onBoomerangLoaded") { // e.detail.BOOMR is a reference to the BOOMR global object init(e.detail.BOOMR); } }); } })();(function() { var article = document.getElementById('article_1-0'); if (article && !article.gtmPageView) { article.gtmPageView = {"description":"With this sample style sheet and CSS cheat sheet, you define the basic styles every time on every website you create.","errorType":"","authorId":"5105","updateDate":"2018-02-14","contentGroup":"Articles","documentId":3466394,"lastEditingAuthorId":"5105","lastEditingUserId":"148131592038192","characterCount":4493,"templateId":"65","socialTitle":"What Is a CSS and What Does It Look Like?","title":"Cascading Style Sheet (CSS) Overview With Sample" || document.title || '',"fullUrl":"https://www.thoughtco.com/css-cheat-sheet-3466394" + location.hash,"experienceType":"single page","currentPageOrdinal":"","previousPageOrdinal":"","entryType":"direct","pageviewType":"standard","templateVariation":"","publishDate":"2007-10-01","numOfImages":1,"numOfPages":1,"numOfArticleWords":"","numOfInlineLinks":"","excludeFromComscore":false,"socialImage":"https://fthmb.tqn.com/oaj67x7gvKtAkDIHc5p6D8qIC3U=/735x0/GettyImages-531346981-5905f2293df78c5456f8e39a.jpg","numOfMapLabels":"","isErrorPage":false,"instartLogicDelivered":0,"internalSessionId":"g1621270231869702d31302d31342d312d31322d311b61d","internalRequestId":"g1621270231869702d31302d31342d312d31322d311b61d","taxonomyNodes":[[{"documentId":4122478,"shortName":"ThoughtCo"},{"documentId":4132465,"shortName":"Science, Tech, Math"},{"documentId":4133486,"shortName":"Computer Science"},{"documentId":4133459,"shortName":"Web Design"}]],"isCommerceDocument":false,"experienceTypeName":""}; } }()); (function() { Mntl.utilities.readyAndDeferred(function($container){ var $masonryInstance = $('#masonry-list1_1-0'); if ($masonryInstance.data('no-js')) return; Mntl.MasonryList.init($container, $masonryInstance, {stretch: '.card__img, .card--no-image .card__content'}); }); })();(function() { Mntl.utilities.readyAndDeferred(function($container){ var $masonryInstance = $('#masonry-list2_1-0'); if ($masonryInstance.data('no-js')) return; Mntl.MasonryList.init($container, $masonryInstance, {stretch: '.card__img, .card--no-image .card__content'}); }); })();

0 comments

Leave a Reply

Your email address will not be published. Required fields are marked *