{"id":3014,"date":"2016-11-06T11:20:08","date_gmt":"2016-11-06T17:20:08","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=1974"},"modified":"2016-11-06T11:20:08","modified_gmt":"2016-11-06T17:20:08","slug":"create-superscript-and-subscript-text-in-css","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/create-superscript-and-subscript-text-in-css\/","title":{"rendered":"Create Superscript and Subscript Text in CSS"},"content":{"rendered":"<p>With CSS3&#8217;s vertical-align property, its super easy to create superscript and subscript effects in your HTML text. Often this is done by using inline HTML tags, but that&#8217;s not really a great practice. Using CSS rather than HTML to achieve this effect makes your code more flexible and dynamic, especially if there are a lot of occurrences of subscript and superscript in your project.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-1978 aligncenter\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-3.15.07-PM.png\" alt=\"Screen Shot 2016-11-06 at 3.15.07 PM\" width=\"650\" height=\"119\" \/><\/p>\n<p>To start, make sure you put the text you want to be subscript or superscript within span tags with corresponding classes. \u00a0Your HTML will probably look something like this:<\/p>\n<pre>&lt;p&gt;Regular text regular text regular text&lt;span class=\"super\"&gt;Superscript&lt;\/span&gt;&lt;\/p&gt;\n&lt;p&gt;Regular text regular text regular text&lt;span class=\"sub\"&gt;Subscript&lt;\/span&gt;&lt;\/p&gt;<\/pre>\n<p>To make them appear as superscript and subscript, you&#8217;ll need to use the vertical-align property in your CSS.<\/p>\n<pre>.super{\n vertical-align: super;\n }\n .sub{\n vertical-align: sub;\n }<\/pre>\n<p>Your initial results should look like this:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-1979 aligncenter\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-3.15.39-PM.png\" alt=\"Screen Shot 2016-11-06 at 3.15.39 PM\" width=\"650\" height=\"129\" \/><\/p>\n<p>As you can see, using the vertical-align property aligns the super or sub text either above or below the regular text, depending on whether use use the sub or super value. To make the text appear more like the footnotes its meant to be, you can also change the font-size to make it smaller. See the results of changing the font size to 11px below:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-1980 aligncenter\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2016\/11\/Screen-Shot-2016-11-06-at-3.17.36-PM.png\" alt=\"Screen Shot 2016-11-06 at 3.17.36 PM\" width=\"652\" height=\"148\" \/><\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>With CSS3&#8217;s vertical-align property, its super easy to create superscript and subscript effects in your HTML text. Often this is done by using inline HTML tags, but that&#8217;s not really a great practice. Using CSS rather than HTML to achieve [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/create-superscript-and-subscript-text-in-css\/\" title=\"Click to read 'Create Superscript and Subscript Text in CSS'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":2776,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[168,173,174],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3014"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=3014"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3014\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/2776"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}