2 Ways to Center content using HTML & CSS

Centering content on a webpage is a common requirement in web development, whether it’s text, images, or entire sections. In this guide, we’ll explore two methods to achieve content centering using HTML and CSS. These methods provide flexibility and can be applied to various elements within your web layout.

Method 1: Using CSS Flexbox

CSS Flexbox is a powerful layout model that simplifies the alignment and distribution of elements within a container. It provides a straightforward way to center content both horizontally and vertically.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Center Content with Flexbox</title>
<style>
  .container {
    display: flex;
    justify-content: center;
    align-items: center; 
    height: 100vh; 
  }
</style>
</head>
<body>
<div class="container">
  <div class="content">
    <h1>Roshan Kumar Jha</h1>
  </div>
</div>
</body>
</html>

Output:-

Method 2: Using CSS Grid

CSS Grid is another layout model that allows for precise control over the positioning and alignment of elements within a grid-based layout. It offers a convenient way to center content using grid properties.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Center Content with CSS Grid</title>
<style>
  .container {
    display: grid;
    place-items: center; 
    height: 100vh; 
  }
</style>
</head>
<body>
<div class="container">
  <div class="content">

    <h1>Roshan Kumar Jha..!</h1>
  </div>
</div>
</body>
</html>

Hopefully, It will help you…!!!

Related Posts

Explore deeper with Certified MLOps Manager monitoring and automation basics

Introduction The gap between developing a machine learning model and deploying it into a reliable production environment is where most artificial intelligence projects fail. The Certified MLOps…

Read More

Certified MLOps Architect: Skills, Syllabus, and Career Opportunities Explained Clearly

Introduction The Certified MLOps Architect is a comprehensive program designed for professionals who want to bridge the gap between machine learning and production engineering. This guide is…

Read More

Advanced Certified MLOps Professional Program for Scalable AI Model Deployment Systems

Introduction The Certified MLOps Professional program from AIOpsSchool has emerged as a vital benchmark for engineers looking to bridge the gap between data science and production engineering….

Read More

Powerful Certified MLOps Engineer Program to Build Reliable ML Infrastructure

Introduction The integration of Machine Learning into production environments has created a significant gap between data science and traditional software engineering. The Certified MLOps Engineer program is…

Read More

Professional Skill Alignment Around MLOps Foundation Certification in Modern Workplaces

Introduction The MLOps Foundation Certification has emerged as a critical benchmark for professionals looking to bridge the gap between data science and production engineering. This guide is…

Read More

Certified AIOps Manager: Strategic Framework for Intelligent IT Operations

Introduction The Certified AIOps Manager program is a specialized training designed to help professionals lead the next wave of IT operations. This guide is for engineers and…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x