To create a responsive website using HTML, you need to use responsive web design techniques. Here's an example of how you can make your HTML code responsive:
html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* Add CSS rules for responsive design */
/* For example: */
.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.responsive-image {
max-width: 100%;
height: auto;
}
@media (max-width: 600px) {
/* CSS rules for screens smaller than 600px */
.container {
padding: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Responsive Website</h1>
<img class="responsive-image" src="image.jpg" alt="Responsive Image">
<p>This is a responsive website.</p>
</div>
</body>
</html>
In the example above, we use CSS media queries to define different styles for different screen sizes. The `meta` tag inside the `head` section sets the viewport to the device's width and initial zoom level.
The `.container` class is set to have a maximum width of 1200 pixels and centered using `margin: 0 auto`. Inside the media query, we change the padding to 10 pixels when the screen width is smaller than 600 pixels.
The `.responsive-image` class ensures that the image scales to fit the width of its container while maintaining its aspect ratio.
By using these techniques and applying responsive CSS rules to your HTML elements, you can create a responsive website that adapts to different screen sizes and devices.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc