What Is CSS (CSS क्या है)
Cascading Style Sheets (CSS) is a style sheet language used for specifying the presentation and styling of a document written in a markup language such as HTML or XML (including XML dialects such as SVG, MathML or XHTML). CSS is a cornerstone technology of the World Wide Web, alongside HTML and JavaScript.
CSS is designed to enable the separation of content and presentation, including layout, colors, and fonts. This separation can improve content accessibility; provide more flexibility and control in the specification of presentation characteristics; enable multiple web pages to share formatting by specifying the relevant CSS in a separate .css file, which reduces complexity and repetition in the structural content; and enable the .css file to be cached to improve the page load speed between the pages that share the file and its formatting.
Example : style.css
Example of CSS source code |
Separation of formatting and content also makes it feasible to present the same markup page in different styles for different rendering methods, such as on-screen, in print, by voice (via speech-based browser or screen reader), and on Braille-based tactile devices. CSS also has rules for alternate formatting if the content is accessed on a mobile device.
The name cascading comes from the specified priority scheme to determine which declaration applies if more than one declaration of a property match a particular element. This cascading priority scheme is predictable.
The CSS specifications are maintained by the World Wide Web Consortium (W3C). Internet media type (MIME type) text/css
is registered for use with CSS by RFC 2318 (March 1998). The W3C operates a free CSS validation service for CSS documents.
In addition to HTML, other markup languages support the use of CSS including XHTML, plain XML, SVG, and XUL. CSS is also used in the GTK widget toolkit.
Example of CSS source code :
Before CSS, nearly all presentational attributes of HTML documents were contained within the HTML markup. All font colors, background styles, element alignments, borders, and sizes had to be explicitly described, often repeatedly, within the HTML. CSS lets authors move much of that information to another file, the style sheet, resulting in considerably simpler HTML. And additionally, as more and more devices are able to access responsive web pages, different screen sizes and layouts begin to appear. Customizing a website for each device size is costly and increasingly difficult. The modular nature of CSS means that styles can be reused in different parts of a site or even across sites, promoting consistency and efficiency.
For example, headings (h1
elements), sub-headings (h2
), sub-sub-headings (h3
), etc., are defined structurally using HTML. In print and on the screen, choice of font, size, color and emphasis for these elements is presentational.
Before CSS, document authors who wanted to assign such typographic characteristics to, say, all h2
headings had to repeat HTML presentational markup for each occurrence
of that heading type. This made documents more complex, larger, and more
error-prone and difficult to maintain. CSS allows the separation of
presentation from structure. CSS can define color, font, text alignment,
size, borders, spacing, layout and many other typographic
characteristics, and can do so independently for on-screen and printed
views. CSS also defines non-visual styles, such as reading speed and
emphasis for aural text readers. The W3C has now deprecated the use of all presentational HTML markup.
For example, under pre-CSS HTML, a heading element defined with red text would be written as:
<h1><font color="red">Chapter 1.</font></h1>
Using CSS, the same element can be coded using style properties instead of HTML presentational attributes:
<h1 style="color: red;">Chapter 1.</h1>
The advantages of this may not be immediately clear but the power of CSS becomes more apparent when the style properties are placed in an internal style element or, even better, an external CSS file. For example, suppose the document contains the style element:
<style>
h1 {
color: red;
}
</style>
All h1
elements in the document will then automatically
become red without requiring any explicit code. If the author later
wanted to make h1
elements blue instead, this could be done by changing the style element to:
<style>
h1 {
color: blue;
}
</style>
rather than by laboriously going through the document and changing the color for each individual h1
element.
The styles can also be placed in an external CSS file, as described below, and loaded using syntax similar to:
<link href="path/to/file.css" rel="stylesheet" type="text/css">
This further decouples the styling from the HTML document and makes it possible to restyle multiple documents by simply editing a shared external CSS file.
Filename extension |
.css |
---|---|
Internet media type |
text/css |
Uniform Type Identifier (UTI) | public.css |
Developed by | World Wide Web Consortium (W3C) |
Initial release | 17 December 1996 |
Latest release | CSS 2.1 : Level 2 Revision 1 12 April 2016 |
Type of format | Style sheet language |
Container for | Style rules for HTML elements (tags) |
Contained by | HTML Documents |
Open format? | Yes |
Post a Comment