{"id":18840,"date":"2020-07-01T00:19:56","date_gmt":"2020-07-01T07:19:56","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=18840"},"modified":"2020-07-24T04:01:04","modified_gmt":"2020-07-24T11:01:04","slug":"css-center","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/css-center\/","title":{"rendered":"Center Elements With CSS Using Text-Align, Margins and More"},"content":{"rendered":"\n<p>In this CSS tutorial, we will go over how to center text and block elements. There are several tricks you can use to center elements horizontally and vertically in a layout.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Center Align Text Elements<\/h2>\n\n\n\n<p>To center align text inside a larger element, use <code>text-align: center;<\/code> as seen below:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n   &lt;meta charset=&quot;UTF-8&quot;&gt;\n   &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n   &lt;title&gt;Center&lt;\/title&gt;\n   &lt;style&gt;\n       .div-class {\n           text-align: center;\n           background-color: lightblue;\n       }\n       button {\n           width: 200px;\n       }\n   &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n   &lt;div class=&quot;div-class&quot;&gt;\n       &lt;p&gt;I'm a paragraph&lt;\/p&gt;\n       &lt;button&gt;I'm a submit button&lt;\/button&gt;\n       &lt;div&gt;I'm a div&lt;\/div&gt;\n       &lt;p&gt;And all the text is being centered by text-align: center&lt;\/p&gt;\n \n   &lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Center Align Block Elements:<\/h2>\n\n\n\n<p>Centering block elements is best illustrated by using the <code>&lt;body><\/code> tag of an HTML document. What you need to do is control the width of the overall container and then set the margin to auto:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n   &lt;meta charset=&quot;UTF-8&quot;&gt;\n   &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n   &lt;title&gt;Center&lt;\/title&gt;\n   &lt;style&gt;\n       body {\n           width: 800px;\n           margin: auto;\n           background: darkcyan;\n           color: white;\n           font-family: 'roboto';\n           padding: 20px;\n       }\n       .div-class {\n           text-align: center;\n           background-color: lightblue;\n           color: black;\n       }\n       button {\n           width: 200px;\n       }\n \n   &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\nI'm the top of the body. I control the width of the app container (in this case 800px) and can center the whole app by using &lt;strong&gt;margin: auto&lt;\/strong&gt;. If you wanted to center &lt;strong&gt;this&lt;\/strong&gt; text, use text-align: center&lt;\/strong&gt;\n   &lt;div class=&quot;div-class&quot;&gt;\n       &lt;p&gt;I'm a paragraph&lt;\/p&gt;\n       &lt;button&gt;I'm a submit button&lt;\/button&gt;\n       &lt;div&gt;I'm a div&lt;\/div&gt;\n       &lt;p&gt;And all the text is being centered by &lt;strong&gt;text-align: center&lt;\/strong&gt;&lt;\/p&gt;\n   &lt;\/div&gt;\n \n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Center Align Image:<\/h2>\n\n\n\n<p>To center an image, in the CSS selector, change your display to block and then control the width of the image element, using <code>%<\/code> or <code>px<\/code>. Set <code>margin<\/code> to <code>auto<\/code>:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n   &lt;meta charset=&quot;UTF-8&quot;&gt;\n   &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n   &lt;title&gt;Center&lt;\/title&gt;\n   &lt;style&gt;\n       body {\n           width: 800px;\n           margin: auto;\n           background: darkcyan;\n           color: white;\n           font-family: 'Roboto';\n           padding: 20px;\n       }\n       .div-class {\n           text-align: center;\n           background-color: lightblue;\n           color: black;\n       }\n       button {\n           width: 200px;\n       }\nimg {\n           display: block;\n           margin: 20px auto;\n           width: 50%;\n       }\n \n \n   &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\nI'm the top of the body. I control the width of the app container (in this case 800px) and can center the whole app by using &lt;strong&gt;margin: auto&lt;\/strong&gt;. If you wanted to center &lt;strong&gt;this&lt;\/strong&gt; text, use text-align: center&lt;\/strong&gt;\n   &lt;div class=&quot;div-class&quot;&gt;\n       &lt;p&gt;I'm a paragraph&lt;\/p&gt;\n       &lt;button&gt;I'm a submit button&lt;\/button&gt;\n       &lt;div&gt;I'm a div&lt;\/div&gt;\n       &lt;p&gt;And all the text is being centered by &lt;strong&gt;text-align: center&lt;\/strong&gt;&lt;\/p&gt;\n   &lt;\/div&gt;\n   &lt;p style=&quot;margin: auto; width: 400px;&quot;&gt;To center image below, change display to block and then set margins to auto, control the width using px or %&lt;\/p&gt;\n   &lt;img src=&quot;http:\/\/www.placekitten.com\/500\/301&quot; alt=&quot;kittens&quot;\/&gt;\n \n \n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Center Vertically and Horizontally in a Div:<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">padding:<\/h4>\n\n\n\n<p>To center vertically in a <code>&lt;div><\/code>, there are several ways to do it. First, and probably the easiest, is to adjust the padding in your <code>&lt;div><\/code> \u2013 you can then use <code>text-align: center <\/code>to center the paragraph horizontally:\u00a0\u00a0<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n   &lt;meta charset=&quot;UTF-8&quot;&gt;\n   &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n   &lt;title&gt;Center&lt;\/title&gt;\n   &lt;style&gt;\n       body {\n           width: 800px;\n           margin: auto;\n           background: darkcyan;\n           color: white;\n           font-family: 'Roboto';\n           padding: 20px;\n       }\n       .div-class {\n           text-align: center;\n           background-color: lightblue;\n           color: black;\n       }\n       button {\n           width: 200px;\n       }\nimg {\n           display: block;\n           margin: 20px auto;\n           width: 50%;\n       }\n \n \n   &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\nI'm the top of the body. I control the width of the app container (in this case 800px) and can center the whole app by using &lt;strong&gt;margin: auto&lt;\/strong&gt;. If you wanted to center &lt;strong&gt;this&lt;\/strong&gt; text, use text-align: center&lt;\/strong&gt;\n   &lt;div class=&quot;div-class&quot;&gt;\n       &lt;p&gt;I'm a paragraph&lt;\/p&gt;\n       &lt;button&gt;I'm a submit button&lt;\/button&gt;\n       &lt;div&gt;I'm a div&lt;\/div&gt;\n       &lt;p&gt;And all the text is being centered by &lt;strong&gt;text-align: center&lt;\/strong&gt;&lt;\/p&gt;\n   &lt;\/div&gt;\n   &lt;p style=&quot;margin: auto; width: 400px;&quot;&gt;To center image below, change display to block and then set margins to auto, control the width using px or %&lt;\/p&gt;\n   &lt;img src=&quot;http:\/\/www.placekitten.com\/500\/301&quot; alt=&quot;kittens&quot;\/&gt;\n \n \n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">line-height:<\/h4>\n\n\n\n<p>You can also set line-height to the height of the block element you are centering in conjunction with text-align: center to align the element to the center. If you have multiple lines, use line-height on both parent and child and add <code>vertical-align: middle<\/code> and <code>display: inline-block <\/code>to the child:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n   &lt;meta charset=&quot;UTF-8&quot;&gt;\n   &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n   &lt;title&gt;Center&lt;\/title&gt;\n   &lt;style&gt;\n       body {\n           width: 800px;\n           margin: auto;\n           background: darkcyan;\n           color: white;\n           font-family: 'roboto';\n           padding: 20px;\n       }\n       #vertical-center-lineheight {\n           line-height: 200px;\n           border: 5px double ivory;\n           text-align: center;\n           margin-bottom: 20px;\n       }\n \n \n   &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n   &lt;div id=&quot;vertical-center-lineheight&quot;&gt;\n       &lt;p&gt;I am vertically centered and horizontally centered in a div using lineheight and text-align: center.&lt;\/p&gt;\n   &lt;\/div&gt;\n   &lt;div id=&quot;vertical-center-lh-multiple&quot;&gt;\n       &lt;p&gt;I am vertically centered and horizontally centered in a div using lineheight, display: inline-block,  and vertical-align: middle. Use me when you have multiple lines of text to center across horizontal and vertical axes. &lt;\/p&gt;\n   &lt;\/div&gt;\n \n \n  \n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">transform:<\/h4>\n\n\n\n<p>Another way you can center elements is by using position and transform. Set the parent element to position: relative, the child element to absolute positioning. The child element will need to be positioned at the top and left at 50% and then we use the transform property to adjust the text in the div. We\u2019ll talk more about this property in another post so it\u2019s all right if it\u2019s not 100 percent clear at the moment:&nbsp;<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n   &lt;meta charset=&quot;UTF-8&quot;&gt;\n   &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n   &lt;title&gt;Center&lt;\/title&gt;\n   &lt;style&gt;\n       body {\n           width: 800px;\n           margin: auto;\n           background: darkcyan;\n           color: white;\n           font-family: 'roboto';\n           padding: 20px;\n       }\n       #vertical-center-transform {\n           height: 200px;\n           position: relative;\n           border: 5px double ivory;\n           margin-bottom: 20px;\n          \n       }\n       #vertical-center-transform p {\n           margin: 0;\n           position: absolute;\n           top: 50%;\n           left: 50%;\n           transform: translate(-50%, -50%);\n       }\n    &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n   &lt;div id=&quot;vertical-center-transform&quot;&gt;\n       &lt;p&gt;I am vertically centered and horizontally centered in a div using transform. Text is &lt;strong&gt;NOT&lt;\/strong&gt; center aligned.&lt;\/p&gt;\n   &lt;\/div&gt;  \n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">flexbox:<\/h4>\n\n\n\n<p>Lastly, we can center elements by using flexbox. Set display: flex to the parent element of the children you would like to center and then use align-items and justify-content to center it:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n   &lt;meta charset=&quot;UTF-8&quot;&gt;\n   &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n   &lt;title&gt;Center&lt;\/title&gt;\n   &lt;style&gt;\n       body {\n           width: 800px;\n           margin: auto;\n           background: darkcyan;\n           color: white;\n           font-family: 'roboto';\n           padding: 20px;\n       }\n       #vertical-center-flexbox {\n           height: 200px;\n           display: flex;\n           align-items: center;\n           justify-content: center;\n           border: 5px double ivory;\n       }\n   &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n   &lt;div id=&quot;vertical-center-flexbox&quot;&gt;\n       &lt;p&gt;I am vertically and horizontally centered in a div using flexbox.&lt;\/p&gt;\n   &lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>These are the most common ways you can solve the problem of centering your elements in your layout.&nbsp;<br><\/p>\n","protected":false},"excerpt":{"rendered":"In this CSS tutorial, we will go over how to center text and block elements. There are several tricks you can use to center elements horizontally and vertically in a layout.&nbsp; Center Align Text Elements To center align text inside a larger element, use text-align: center; as seen below: &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta&hellip;","protected":false},"author":77,"featured_media":18890,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17287],"tags":[],"class_list":{"0":"post-18840","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-css"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"CSS","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":[],"is_guest_post":[]},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>CSS Tutorial: CSS Center Text and Blocks<\/title>\n<meta name=\"description\" content=\"Text-align, margin and vertical-align are all ways we can use CSS to center content in a block element. Find out more about these properties here.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/css-center\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Center Elements With CSS Using Text-Align, Margins and More\" \/>\n<meta property=\"og:description\" content=\"Text-align, margin and vertical-align are all ways we can use CSS to center content in a block element. Find out more about these properties here.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/css-center\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-01T07:19:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-24T11:01:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"750\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Christina Kopecky\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christina Kopecky\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/\"},\"author\":{\"name\":\"Christina Kopecky\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e\"},\"headline\":\"Center Elements With CSS Using Text-Align, Margins and More\",\"datePublished\":\"2020-07-01T07:19:56+00:00\",\"dateModified\":\"2020-07-24T11:01:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/\"},\"wordCount\":342,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg\",\"articleSection\":[\"CSS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/css-center\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/css-center\/\",\"name\":\"CSS Tutorial: CSS Center Text and Blocks\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg\",\"datePublished\":\"2020-07-01T07:19:56+00:00\",\"dateModified\":\"2020-07-24T11:01:04+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e\"},\"description\":\"Text-align, margin and vertical-align are all ways we can use CSS to center content in a block element. Find out more about these properties here.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/css-center\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg\",\"width\":1000,\"height\":750},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/css-center\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS\",\"item\":\"https:\/\/careerkarma.com\/blog\/css\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Center Elements With CSS Using Text-Align, Margins and More\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e\",\"name\":\"Christina Kopecky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg\",\"caption\":\"Christina Kopecky\"},\"description\":\"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.\",\"sameAs\":[\"http:\/\/www.linkedin.com\/in\/cmvnk\"],\"url\":\"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"CSS Tutorial: CSS Center Text and Blocks","description":"Text-align, margin and vertical-align are all ways we can use CSS to center content in a block element. Find out more about these properties here.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/css-center\/","og_locale":"en_US","og_type":"article","og_title":"Center Elements With CSS Using Text-Align, Margins and More","og_description":"Text-align, margin and vertical-align are all ways we can use CSS to center content in a block element. Find out more about these properties here.","og_url":"https:\/\/careerkarma.com\/blog\/css-center\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-01T07:19:56+00:00","article_modified_time":"2020-07-24T11:01:04+00:00","og_image":[{"width":1000,"height":750,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg","type":"image\/jpeg"}],"author":"Christina Kopecky","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"Christina Kopecky","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/css-center\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/css-center\/"},"author":{"name":"Christina Kopecky","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"headline":"Center Elements With CSS Using Text-Align, Margins and More","datePublished":"2020-07-01T07:19:56+00:00","dateModified":"2020-07-24T11:01:04+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/css-center\/"},"wordCount":342,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/css-center\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg","articleSection":["CSS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/css-center\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/css-center\/","url":"https:\/\/careerkarma.com\/blog\/css-center\/","name":"CSS Tutorial: CSS Center Text and Blocks","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/css-center\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/css-center\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg","datePublished":"2020-07-01T07:19:56+00:00","dateModified":"2020-07-24T11:01:04+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"description":"Text-align, margin and vertical-align are all ways we can use CSS to center content in a block element. Find out more about these properties here.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/css-center\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/css-center\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/css-center\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/black-board-bright-bullseye-226569.jpg","width":1000,"height":750},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/css-center\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"CSS","item":"https:\/\/careerkarma.com\/blog\/css\/"},{"@type":"ListItem","position":3,"name":"Center Elements With CSS Using Text-Align, Margins and More"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e","name":"Christina Kopecky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","caption":"Christina Kopecky"},"description":"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.","sameAs":["http:\/\/www.linkedin.com\/in\/cmvnk"],"url":"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/18840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=18840"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/18840\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/18890"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=18840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=18840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=18840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}