CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of a document written in HTML or XML.
- CSS allows you to control the layout of multiple web pages all at once, saving a lot of work.
- It enables the separation of content from design, making maintenance easier and providing more flexibility in presentation.
- CSS enhances the accessibility of web pages by allowing for responsive designs that adapt to different screen sizes and devices.
Here are some key applications of CSS:
1. Styling Web Pages: CSS allows for the application of various styles to HTML elements, including fonts, colors, and layouts, enhancing the visual appeal of web pages.
2. Responsive Design: By using media queries, CSS enables web pages to adapt to different screen sizes and devices, ensuring a consistent user experience across platforms.
3. Consistency Across Pages: External CSS files can be linked to multiple HTML documents, allowing for uniform styling across a website and simplifying maintenance.
4. Accessibility Improvement: CSS facilitates the creation of accessible web content by allowing adjustments in presentation without altering the underlying HTML, catering to users with diverse needs.
5. Animation and Interactivity: CSS supports animations and transitions, enabling interactive elements without relying solely on JavaScript
Responsive Web Page Using CSS
HTML
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
}
.container {
text-align: center;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
img {
max-width: 100%;
height: auto;
border-radius: 8px;
}
@media (max-width: 600px) {
.container {
padding: 10px;
}
h2 {
font-size: 1.5em;
}
p {
font-size: 1em;
}
}
</style>
</head>
<body>
<div class="container">
<h2>Responsive Design Example</h2>
<img src="https://media.geeksforgeeks.org/wp-content/uploads/20231106133657/gfg_logo.png"
alt="Logo">
<p>Resize the browser window to see the responsive effect.</p>
</div>
</body>
</html>
In this example,
- The <meta name="viewport" content="width=device-width, initial-scale=1.0"> tag ensures the page scales correctly on different devices.
- The CSS within the <style> tag styles the page and includes a media query that adjusts the layout for screens narrower than 600 pixels.
Output:
output
Similar Reads
Pure CSS Pure CSS is a CSS framework. It is a set of free and open-source tools for building responsive websites and web applications. Yahoo developed this, which is used to make websites that are quicker, more elegant, and more responsive. It is a viable alternative to Bootstrap. Pure CSS is designed with k
2 min read
CSS Fonts CSS fonts control how text appears on a webpage. With CSS, you can specify various properties like font family, size, weight, style, and line height to create visually appealing and readable typographyKey Properties of CSS FontsTo customize fonts effectively in web design, itâs crucial to understand
4 min read
CSS Full Form The full form of CSS is Cascading Style Sheets. It is a style sheet language used to add styles to HTML documents displayed in browsers. CSS enhances the user experience by making web pages more attractive and user-friendly. Developed by the World Wide Web Consortium (W3C) in 1996.Table of ContentWh
3 min read
CSS Selectors CSS Selectors are used to target HTML elements on your pages, allowing you to apply styles based on their ID, class, type attributes, and more. There are mainly 5 types of selectors.Basic CSS Selectors: These are used to target elements by tag, .class, or # ID for fundamental styling needs.Combinato
7 min read
CSS Frameworks CSS Frameworks are pre-written libraries that simplify and speed up the process of designing responsive, visually consistent web interfaces. They offer ready-to-use components and grid systems, helping developers avoid repetitive CSS from scratch.CSS FrameworksIt provides a solid foundation for buid
7 min read
CSS * (Universal) Selector The universal selector (*) applies styles to all elements on a page or within a specified context, regardless of their type, class, or ID. It's commonly used for global resets or universal styling. * { /* styles */}1. Basic Use case of universal selectorThe universal selector applies styles to all e
4 min read