Science, Tech, Math › Computer Science Center a Document With a Fixed Width Layout Using CSS Share Flipboard Email Print Science, Tech, Math PHP Programming Perl Python Java Programming Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Jennifer Kyrnin Jennifer Kyrnin Writer University of California University of Washington Jennifer Kyrnin is a professional web developer who assists others in learning web design, HTML, CSS, and XML. Learn about our Editorial Process Updated on March 13, 2019 Fixed width layouts can be hard to center with some of the popular browsers out there, but it is possible, with only a few lines of code. Here's How Create a new web page with a CSS stylesheet in your HTML editor. Create a div element as the main element on the page where you'll store everything on the page. Give that div element an ID that is unique on the page. Open your CSS style sheet and set the width of your div element:div#main { width: 750px; } Add automatic margins to center your div:div#main { width: 750px; margin-left: auto; margin-right: auto } To fix it for Netscape 4, and IE 4 - 6 (quirks mode) add a text-align on the body:body { text-align: center; } But then all the text inside is centered, so re-align the text in your #main div by adding text-align: left; in there:div#main { width: 750px; margin-left: auto; margin-right: auto; text-align: left; } Save your page and your stylesheet. Test your work in several web browsers. This will center the layout box but not the content within it. Use text-align to center the inner content. Cite this Article Format mla apa chicago Your Citation Kyrnin, Jennifer. "Center a Document With a Fixed Width Layout Using CSS." ThoughtCo, Jul. 31, 2021, thoughtco.com/center-document-with-fixed-width-layout-3466906. Kyrnin, Jennifer. (2021, July 31). Center a Document With a Fixed Width Layout Using CSS. Retrieved from https://www.thoughtco.com/center-document-with-fixed-width-layout-3466906 Kyrnin, Jennifer. "Center a Document With a Fixed Width Layout Using CSS." ThoughtCo. https://www.thoughtco.com/center-document-with-fixed-width-layout-3466906 (accessed June 4, 2023). copy citation