

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I center <div> tag using CSS?
Example
<html> <head> <title>div in center without css</title> </head> <body> <div> THIS IS ONE PARAGRAPH. HERE WE ARE NOT USE ANY ALIGNMENT. </div> <div align="center" style="border: 2px solid blue"> THIS PARAGRAPH IS IN CENTER </div> </body> </html>
Example
<html> <head> <title>div in center with css</title> <link href="../../Content/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div> THIS IS ONE PARAGRAPH. HERE WE ARE NOT USE ANY ALIGNMENT. </div> <div class="mydiv"> THIS PARAGRAPH IS IN CENTER </div> </body> </html>
Style.css
body { background-color:Gray; } .mydiv { padding:10px; margin:auto; width:30%; border:4px solid black; }
If you want to text is also center in the box.then write text-align:center in .mydiv class within CSS file.
- Related Questions & Answers
- HTML <center> Tag
- How to horizontally center a <div> in another <div>?
- How do we style HTML elements using the division tag <div>?
- HTML <i> Tag
- How do I wrap text in a <pre> tag in HTML?
- Selects all <p> elements inside <div> elements with CSS
- How do we do variable formatting using the <var> tag in HTML?
- Selects all <div> elements and all <p> elements with CSS
- How can I remove everything inside of a <div> using jQuery?
- '></a></li></ul><i>xssi</i>
- How do we style HTML elements using the span tag <span>?
- How do we do computer output formatting using the <samp> tag in HTML?
- <radialGradient> HTML5 tag
- HTML <code> Tag
- HTML <datalist> Tag
Advertisements