W3Schools.com


  
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE... REFERENCES | EXAMPLES | FORUM | ABOUT

CSS Syntax

« Previous Next Chapter »

Examples


CSS Syntax

A CSS rule has two main parts: a selector, and one or more declarations:

The selector is normally the HTML element you want to style.

Each declaration consists of a property and a value.

The property is the style attribute you want to change. Each property has a value.


CSS Example

CSS declarations always ends with a semicolon, and declaration groups are surrounded by curly brackets:

p {color:red;text-align:center;}

To make the CSS more readable, you can put one declaration on each line, like this:

Example

p
{
color:red;
text-align:center;
}

Try it yourself »


CSS Comments

Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers.

A CSS comment begins with "/*", and ends with "*/", like this:

/*This is a comment*/
p
{
text-align:center;
/*This is another comment*/
color:black;
font-family:arial;
}

« Previous Next Chapter »


Create Your Own Website Like a Pro

Start Creating a stunning, Flash website. It's easy and free!

Wix.com offers you a simple, powerful, drag & drop editing platform to create stunning Flash websites, layouts, and more.

With added e-commerce features such as search engine visibility and professional tools, Wix is the ultimate solution for creating a spectacular site.


 

W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 6000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML, XHTML, and CSS.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
Top Web Hosting
$1 Domain Sale
WEB BUILDING
Download XML Editor
FREE Flash Website
6,000+ HTML Templates
Download now (FREE)
Advertise on Google
Stand out on Google search and maps Click Here
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE