What Is CSS?: Cascading Style Sheets, Fondly Referred To As CSS, Is A Simple
What Is CSS?: Cascading Style Sheets, Fondly Referred To As CSS, Is A Simple
In the early days of the World Wide Web (WWW), it was common for HTML
files to include not only markup language and content, but formatting
information and JavaScript as well. This made webpages difficult to write,
difficult to read, difficult to update and difficult to maintain. As the web
matured, it became a best practice to divide HTML, scripting content and style
information into separate, easy-to-maintain files. As such, a modern webpage
is typically made up of three separate entities: a cascading style sheet,
a JavaScript file and the HTML file itself.
Example of CSS
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
h1 {
color: white;
text-align: center;
p{
font-family: verdana;
font-size: 20px;
</style>
</head>
<body>
<p>This is a paragraph.</p>
</body>
</html>
Cascading Style Sheet(CSS) is used to set the style in web pages which contain
HTML elements. It sets the background color, font-size, font-family, color, … etc
property of elements in a web pages.
There are three types of CSS which are given below:
Inline CSS
Internal or Embedded CSS
External CSS
Inline CSS: Inline CSS contains the CSS property in the body section attached with
element is known as inline CSS. This kind of style is specified within an HTML tag
using style attribute.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Inline CSS</title>
</head>
<body>
<p style = "color:#009900;
font-size:50px;
font-style:italic;
text-align:center;">
GeeksForGeeks</p>
</body>
</html>
Internal or Embedded CSS: This can be used when a single HTML document must be
styled uniquely. The CSS rule set should be within the HTML file in the head section i.e
the CSS is embedded within the HTML file.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Internal CSS</title>
<style>
.main {
text-align:center;
}
.GFG {
color:#009900;
font-size:50px;
font-weight:bold;
}
.geeks {
font-style:bold;
font-size:20px;
}
</style>
</head>
<body>
<div class = "main">
<div class ="GFG">GeeksForGeeks</div>
<div class ="geeks">A computer science portal for
geeks</p>
</div>
</body>
</html>
External CSS: External CSS contains separate CSS file which contains only style
property with the help of tag attributes (For example class, id, heading, … etc). CSS
property written in a separate file with .css extension and should be linked to the
HTML document using link tag. This means that for each element, style can be set
only once and that will be applied across web pages.
Example: The file given below contains CSS property. This file save with .css
extension. For Ex: geeks.css
body {
background-color:powderblue;
.main {
text-align:center;
.GFG {
color:#009900;
font-size:50px;
font-weight:bold;
#geeks {
font-style:bold;
font-size:20px;
}
Advantages of CSS
The Style Sheets specification works by allowing you to specify
rules that say how the content of elements within your document
should appear. Converting from an HTML page to a CSS design page
may be a bit difficult and time consuming task. However, Cascading
Style Sheet design has many advantages and benefits. Following are
some major advantages associated with using CSS for web design.
Style Sheets can exactly positions your element where ever you want
in the web page. It allows you to put a layer on a specific place on
your screen, so that it stays the same no matter what screen resolution
or browser window sizes a viewer uses. In any phase of web
development, the developer feels that particular Styles are not going
well with the situation then it becomes easier for them to position
them easily using Style Sheets.
Style Sheets can be used to create printer friendly web pages. CSS
enabled web pages can be easily printed. The colors, images and other
things which are difficult to be printed can be eliminated and printed
easily by Style Sheets.
Advantages of CSS
Cross-Browser Issues
Implementing initial CSS changes on a website is easy on the developer’s end.
However, after the changes have been made, you will have to confirm the
compatibility if the CSS is displaying similar change effects on all the browsers.
This is simply due to the fact that CSS works differently on different browsers.
Vulnerable
If you have worked with CSS, you probably know that it is easily accessible
because of its open text-based system. An accident or a mere act of mischief
with the files can end up disrupting the display and formatting of your entire
website. It would only require a read/write access to the intended website to
override the changes.