css type to add in website


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


Browser uses Cascading and inheritance to determine which values to use for properties when displaying an element.


Each element has a number of CSS properties.


For each of those properties, the browser needs to step through all of the sources of styles it has.


Three Ways to Insert CSS


  • External style sheet
  • Internal style sheet
  • Inline style

There are two other sources of styles that you need to know about.


The browser styles or user agent styles are the default styles a browser applies to an element if no other style has been specified.


These styles vary slightly between browsers.


External Style Sheet


An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing just one file.


Each page must include a link to the style sheet with the <link> tag. The <link> tag goes inside the head section:


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

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. An example of a style sheet file called "myStyle.css", is shown below:


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

Internal Style Sheet


An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, inside the <style> tag, like this:


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

Inline Styles


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


To use inline styles, add the style attribute to the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a h1 element:


	      	<h1 style="color:blue;margin-left:30px;">This is a heading.</h1>
	      

Multiple Style Sheets


If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet.


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

The left margin is inherited from the external style sheet and the color is replaced by the internal style sheet.


Multiple Styles Will Cascade into One


  • inside an HTML element
  • inside the <head> section of an HTML page
  • in an external CSS file

Even multiple external style sheets can be referenced inside a single HTML document.


Cascading order


  • Browser default
  • External style sheet
  • Internal style sheet (in the head section)
  • Inline style (inside an HTML element)

So, an inline style (inside an 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 in a browser (a default value).


If the link to the external style sheet is placed after the internal style sheet in HTML <head>, the external style sheet will override the internal style sheet!