Introduction to CSS




What is CSS?

CSS is the language we use to style an HTML document. CSS describes how HTML elements should be displayed.

CSS Syntax

A CSS rule set consists of a selector and a declaration block:

Example Explained:

CSS How To ...

When a browser reads a style sheet, it will format the HTML document according to the information in the style sheet. There are three ways of inserting a style sheet:

Inline style


			<p>This is a paragraph.</p>
<p style="color: #b31fb5;text-align: center; font-size: 40px;">This is a paragraph with inline style</p>
		

This is a paragraph.

This is a paragraph with inline style

Internal Style Sheet


	<style>
    	p{ 
        color: #b31fb5;
        text-align: center;
	font-size: 40px;
      	}
    	</style>
		

External Style Sheet


Cascading Order

CSS color

Text alignment

Font size

Font family

CSS Background

Comment

HTML block

Examples

			<div>
  			<p>A paragraph inside div</p>
			</div>
		
    <div style="width: 50px; height: 50px; background-color: red"></div>
    <div style="width: 50px; height: 50px; background-color: green"></div>
    <div style="width: 50px; height: 50px; background-color: blue"></div>
    <div style="width: 50px; height: 50px; background-color: yellow"></div>
		

Spantastic

Reference