Ionic Framework provides a set of CSS utility classes that can be used on any element in order to modify the text, element placement or adjust the padding and margin.

If your app was not started using an available Ionic Framework starter, the stylesheets listed in the optional section of the global stylesheets will need to be included in order for these styles to work.

Text Modification

Text Alignment

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col>
  4. <div class="ion-text-start">
  5. <h3>text-start</h3>
  6. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  7. </div>
  8. </ion-col>
  9. <ion-col>
  10. <div class="ion-text-end">
  11. <h3>text-end</h3>
  12. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  13. </div>
  14. </ion-col>
  15. <ion-col>
  16. <div class="ion-text-center">
  17. <h3>text-center</h3>
  18. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  19. </div>
  20. </ion-col>
  21. </ion-row>
  22. <ion-row>
  23. <ion-col>
  24. <div class="ion-text-justify">
  25. <h3>text-justify</h3>
  26. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  27. </div>
  28. </ion-col>
  29. <ion-col>
  30. <div class="ion-text-wrap">
  31. <h3>text-wrap</h3>
  32. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  33. </div>
  34. </ion-col>
  35. <ion-col>
  36. <div class="ion-text-nowrap">
  37. <h3>text-nowrap</h3>
  38. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  39. </div>
  40. </ion-col>
  41. </ion-row>
  42. </ion-grid>

ClassStyle RuleDescription
.ion-text-lefttext-align: leftThe inline contents are aligned to the left edge of the line box.
.ion-text-righttext-align: rightThe inline contents are aligned to the right edge of the line box.
.ion-text-starttext-align: startThe same as text-left if direction is left-to-right and text-right if direction is right-to-left.
.ion-text-endtext-align: endThe same as text-right if direction is left-to-right and text-left if direction is right-to-left.
.ion-text-centertext-align: centerThe inline contents are centered within the line box.
.ion-text-justifytext-align: justifyThe inline contents are justified. Text should be spaced to line up its left and right edges to the left and right edges of the line box, except for the last line.
.ion-text-wrapwhite-space: normalSequences of whitespace are collapsed. Newline characters in the source are handled as other whitespace. Breaks lines as necessary to fill line boxes.
.ion-text-nowrapwhite-space: nowrapCollapses whitespace as for normal, but suppresses line breaks (text wrapping) within text.

Text Transformation

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col>
  4. <div class="ion-text-uppercase">
  5. <h3>text-uppercase</h3>
  6. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  7. </div>
  8. </ion-col>
  9. <ion-col>
  10. <div class="ion-text-lowercase">
  11. <h3>text-lowercase</h3>
  12. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  13. </div>
  14. </ion-col>
  15. <ion-col>
  16. <div class="ion-text-capitalize">
  17. <h3>text-capitalize</h3>
  18. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  19. </div>
  20. </ion-col>
  21. </ion-row>
  22. </ion-grid>

ClassStyle RuleDescription
.ion-text-uppercasetext-transform: uppercaseForces all characters to be converted to uppercase.
.ion-text-lowercasetext-transform: lowercaseForces all characters to be converted to lowercase.
.ion-text-capitalizetext-transform: capitalizeForces the first letter of each word to be converted to uppercase.

Responsive Text Classes

All of the text classes listed above have additional classes to modify the text based on the screen size. Instead of text- in each class, use text-{breakpoint}- to only use the class on specific screen sizes, where {breakpoint} is one of the breakpoint names listed in Ionic Breakpoints.

The table below shows the default behavior, where {modifier} is any of the following: left, right, start, end, center, justify, wrap, nowrap, uppercase, lowercase, or capitalize, as they are described above.

ClassDescription
.ion-text-{modifier}Applies the modifier to the element on all screen sizes.
.ion-text-sm-{modifier}Applies the modifier to the element when min-width: 576px.
.ion-text-md-{modifier}Applies the modifier to the element when min-width: 768px.
.ion-text-lg-{modifier}Applies the modifier to the element when min-width: 992px.
.ion-text-xl-{modifier}Applies the modifier to the element when min-width: 1200px.

Element Placement

Float Elements

The float CSS property specifies that an element should be placed along the left or right side of its container, where text and inline elements will wrap around it. This way, the element is taken from the normal flow of the web page, though still remaining a part of the flow, contrary to absolute positioning.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col class="ion-float-left">
  4. <div>
  5. <h3>float-left</h3>
  6. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  7. </div>
  8. </ion-col>
  9. <ion-col class="ion-float-right">
  10. <div>
  11. <h3>float-right</h3>
  12. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac vehicula lorem.
  13. </div>
  14. </ion-col>
  15. </ion-row>
  16. </ion-grid>

ClassStyle RuleDescription
.ion-float-leftfloat: leftThe element will float on the left side of its containing block.
.ion-float-rightfloat: rightThe element will float on the right side of its containing block.
.ion-float-startfloat: left / float: rightThe same as float-left if direction is left-to-right and float-right if direction is right-to-left.
.ion-float-endfloat: left / float: rightThe same as float-right if direction is left-to-right and float-left if direction is right-to-left.

Responsive Float Classes

All of the float classes listed above have additional classes to modify the float based on the screen size. Instead of float- in each class, use float-{breakpoint}- to only use the class on specific screen sizes, where {breakpoint} is one of the breakpoint names listed in Ionic Breakpoints.

The table below shows the default behavior, where {modifier} is any of the following: left, right, start, or end, as they are described above.

ClassDescription
.ion-float-{modifier}Applies the modifier to the element on all screen sizes.
.ion-float-sm-{modifier}Applies the modifier to the element when min-width: 576px.
.ion-float-md-{modifier}Applies the modifier to the element when min-width: 768px.
.ion-float-lg-{modifier}Applies the modifier to the element when min-width: 992px.
.ion-float-xl-{modifier}Applies the modifier to the element when min-width: 1200px.

Element Display

The display CSS property determines if an element should be visible or not. The element will still be in the DOM, but not rendered, if it is hidden.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col class="ion-hide">
  4. <div>
  5. <h3>hidden</h3>
  6. You can't see me.
  7. </div>
  8. </ion-col>
  9. <ion-col>
  10. <div>
  11. <h3>not-hidden</h3>
  12. You can see me!
  13. </div>
  14. </ion-col>
  15. </ion-row>
  16. </ion-grid>

ClassStyle RuleDescription
.ion-hidedisplay: noneThe element will be hidden.

Responsive Display Attributes

There are also additional classes to modify the visibility based on the screen size. Instead of just .ion-hide for all screen sizes, use .ion-hide-{breakpoint}-{dir} to only use the class on specific screen sizes, where {breakpoint} is one of the breakpoint names listed in Ionic Breakpoints, and {dir} is whether the element should be hidden on all screen sizes above (up) or below (down) the specified breakpoint.

ClassDescription
.ion-hide-sm-{dir}Applies the modifier to the element when min-width: 576px (up) or max-width: 576px (down).
.ion-hide-md-{dir}Applies the modifier to the element when min-width: 768px (up) or max-width: 768px (down).
.ion-hide-lg-{dir}Applies the modifier to the element when min-width: 992px (up) or max-width: 992px (down).
.ion-hide-xl-{dir}Applies the modifier to the element when min-width: 1200px (up) or max-width: 1200px (down).

Content Space

Element Padding

The padding class sets the padding area of an element. The padding area is the space between the content of the element and its border.

The default amount of padding to be applied is 16px and is set by the —ion-padding variable. See the CSS Variables section for more information on how to change these values.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col class="ion-padding">
  4. <div>
  5. padding
  6. </div>
  7. </ion-col>
  8. <ion-col class="ion-padding-top">
  9. <div>
  10. padding-top
  11. </div>
  12. </ion-col>
  13. <ion-col class="ion-padding-start">
  14. <div>
  15. padding-start
  16. </div>
  17. </ion-col>
  18. <ion-col class="ion-padding-end">
  19. <div>
  20. padding-end
  21. </div>
  22. </ion-col>
  23. </ion-row>
  24. <ion-row>
  25. <ion-col class="ion-padding-bottom">
  26. <div>
  27. padding-bottom
  28. </div>
  29. </ion-col>
  30. <ion-col class="ion-padding-vertical">
  31. <div>
  32. padding-vertical
  33. </div>
  34. </ion-col>
  35. <ion-col class="ion-padding-horizontal">
  36. <div>
  37. padding-horizontal
  38. </div>
  39. </ion-col>
  40. <ion-col class="ion-no-padding">
  41. <div>
  42. no-padding
  43. </div>
  44. </ion-col>
  45. </ion-row>
  46. </ion-grid>

ClassStyle RuleDescription
.ion-paddingpadding: 16pxApplies padding to all sides.
.ion-padding-toppadding-top: 16pxApplies padding to the top.
.ion-padding-startpadding-start: 16pxApplies padding to the start.
.ion-padding-endpadding-end: 16pxApplies padding to the end.
.ion-padding-bottompadding-bottom: 16pxApplies padding to the bottom.
.ion-padding-verticalpadding: 16px 0Applies padding to the top and bottom.
.ion-padding-horizontalpadding: 0 16pxApplies padding to the left and right.
.ion-no-paddingpadding: 0Applies no padding to all sides.

Element Margin

The margin area extends the border area with an empty area used to separate the element from its neighbors.

The default amount of margin to be applied is 16px and is set by the —ion-margin variable. See the CSS Variables section for more information on how to change these values.

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col class="ion-margin">
  4. <div>
  5. margin
  6. </div>
  7. </ion-col>
  8. <ion-col class="ion-margin-top">
  9. <div>
  10. margin-top
  11. </div>
  12. </ion-col>
  13. <ion-col class="ion-margin-start">
  14. <div>
  15. margin-start
  16. </div>
  17. </ion-col>
  18. <ion-col class="ion-margin-end">
  19. <div>
  20. margin-end
  21. </div>
  22. </ion-col>
  23. </ion-row>
  24. <ion-row>
  25. <ion-col class="ion-margin-bottom">
  26. <div>
  27. margin-bottom
  28. </div>
  29. </ion-col>
  30. <ion-col class="ion-margin-vertical">
  31. <div>
  32. margin-vertical
  33. </div>
  34. </ion-col>
  35. <ion-col class="ion-margin-horizontal">
  36. <div>
  37. margin-horizontal
  38. </div>
  39. </ion-col>
  40. <ion-col class="ion-no-margin">
  41. <div>
  42. no-margin
  43. </div>
  44. </ion-col>
  45. </ion-row>
  46. </ion-grid>

ClassStyle RuleDescription
.ion-marginmargin: 16pxApplies margin to all sides.
.ion-margin-topmargin-top: 16pxApplies margin to the top.
.ion-margin-startmargin-start: 16pxApplies margin to the left.
.ion-margin-endmargin-end: 16pxApplies margin to the right.
.ion-margin-bottommargin-bottom: 16pxApplies margin to the bottom.
.ion-margin-verticalmargin: 16px 0Applies margin to the top and bottom.
.ion-margin-horizontalmargin: 0 16pxApplies margin to the left and right.
.ion-no-marginmargin: 0Applies no margin to all sides.

Flex Properties

CSS Utilities - 图1

Flex Container Properties

  1. <ion-grid>
  2. <ion-row class="ion-justify-content-start">
  3. <ion-col size="3">
  4. <div>
  5. 1 of 2
  6. </div>
  7. </ion-col>
  8. <ion-col size="3">
  9. <div>
  10. 2 of 2
  11. </div>
  12. </ion-col>
  13. </ion-row>
  14. <ion-row class="ion-justify-content-center">
  15. <ion-col size="3">
  16. <div>
  17. 1 of 2
  18. </div>
  19. </ion-col>
  20. <ion-col size="3">
  21. <div>
  22. 2 of 2
  23. </div>
  24. </ion-col>
  25. </ion-row>
  26. <ion-row class="ion-justify-content-end">
  27. <ion-col size="3">
  28. <div>
  29. 1 of 2
  30. </div>
  31. </ion-col>
  32. <ion-col size="3">
  33. <div>
  34. 2 of 2
  35. </div>
  36. </ion-col>
  37. </ion-row>
  38. <ion-row class="ion-justify-content-around">
  39. <ion-col size="3">
  40. <div>
  41. 1 of 2
  42. </div>
  43. </ion-col>
  44. <ion-col size="3">
  45. <div>
  46. 2 of 2
  47. </div>
  48. </ion-col>
  49. </ion-row>
  50. <ion-row class="ion-justify-content-between">
  51. <ion-col size="3">
  52. <div>
  53. 1 of 2
  54. </div>
  55. </ion-col>
  56. <ion-col size="3">
  57. <div>
  58. 2 of 2
  59. </div>
  60. </ion-col>
  61. </ion-row>
  62. <ion-row class="ion-justify-content-evenly">
  63. <ion-col size="3">
  64. <div>
  65. 1 of 2
  66. </div>
  67. </ion-col>
  68. <ion-col size="3">
  69. <div>
  70. 2 of 2
  71. </div>
  72. </ion-col>
  73. </ion-row>
  74. </ion-grid>
  75. <ion-grid>
  76. <ion-row class="ion-align-items-start">
  77. <ion-col>
  78. <div>
  79. 1 of 4
  80. </div>
  81. </ion-col>
  82. <ion-col>
  83. <div>
  84. 2 of 4
  85. </div>
  86. </ion-col>
  87. <ion-col>
  88. <div>
  89. 3 of 4
  90. </div>
  91. </ion-col>
  92. <ion-col>
  93. <div>
  94. 4 of 4 <br>
  95. # <br>
  96. # <br>
  97. #
  98. </div>
  99. </ion-col>
  100. </ion-row>
  101. <ion-row class="ion-align-items-end">
  102. <ion-col>
  103. <div>
  104. 1 of 4
  105. </div>
  106. </ion-col>
  107. <ion-col>
  108. <div>
  109. 2 of 4
  110. </div>
  111. </ion-col>
  112. <ion-col>
  113. <div>
  114. 3 of 4
  115. </div>
  116. </ion-col>
  117. <ion-col>
  118. <div>
  119. 4 of 4 <br>
  120. # <br>
  121. # <br>
  122. #
  123. </div>
  124. </ion-col>
  125. </ion-row>
  126. <ion-row class="ion-align-items-center">
  127. <ion-col>
  128. <div>
  129. 1 of 4
  130. </div>
  131. </ion-col>
  132. <ion-col>
  133. <div>
  134. 2 of 4
  135. </div>
  136. </ion-col>
  137. <ion-col>
  138. <div>
  139. 3 of 4
  140. </div>
  141. </ion-col>
  142. <ion-col>
  143. <div>
  144. 4 of 4 <br>
  145. # <br>
  146. # <br>
  147. #
  148. </div>
  149. </ion-col>
  150. </ion-row>
  151. <ion-row class="ion-align-items-baseline">
  152. <ion-col>
  153. <div>
  154. 1 of 4
  155. </div>
  156. </ion-col>
  157. <ion-col>
  158. <div>
  159. 2 of 4
  160. </div>
  161. </ion-col>
  162. <ion-col>
  163. <div>
  164. 3 of 4
  165. </div>
  166. </ion-col>
  167. <ion-col>
  168. <div>
  169. 4 of 4 <br>
  170. # <br>
  171. # <br>
  172. #
  173. </div>
  174. </ion-col>
  175. </ion-row>
  176. <ion-row class="ion-align-items-stretch">
  177. <ion-col>
  178. <div>
  179. 1 of 4
  180. </div>
  181. </ion-col>
  182. <ion-col>
  183. <div>
  184. 2 of 4
  185. </div>
  186. </ion-col>
  187. <ion-col>
  188. <div>
  189. 3 of 4
  190. </div>
  191. </ion-col>
  192. <ion-col>
  193. <div>
  194. 4 of 4 <br>
  195. # <br>
  196. # <br>
  197. #
  198. </div>
  199. </ion-col>
  200. </ion-row>
  201. </ion-grid>

ClassStyle RuleDescription
.ion-justify-content-startjustify-content: flex-startItems are packed toward the start on the main axis.
.ion-justify-content-endjustify-content: flex-endItems are packed toward the end on the main axis.
.ion-justify-content-centerjustify-content: centerItems are centered along the main axis.
.ion-justify-content-aroundjustify-content: space-aroundItems are evenly distributed on the main axis with equal space around them.
.ion-justify-content-betweenjustify-content: space-betweenItems are evenly distributed on the main axis.
.ion-justify-content-evenlyjustify-content: space-evenlyItems are distributed so that the spacing between any two items is equal.
.ion-align-items-startalign-items: flex-startItems are packed toward the start on the cross axis.
.ion-align-items-endalign-items: flex-endItems are packed toward the end on the cross axis.
.ion-align-items-centeralign-items: centerItems are centered along the cross axis.
.ion-align-items-baselinealign-items: baselineItems are aligned so that their baselines align.
.ion-align-items-stretchalign-items: stretchItems are stretched to fill the container.
.ion-nowrapflex-wrap: nowrapItems will all be on one line.
.ion-wrapflex-wrap: wrapItems will wrap onto multiple lines, from top to bottom.
.ion-wrap-reverseflex-wrap: wrap-reverseItems will wrap onto multiple lines, from bottom to top.

Flex Item Properties

  1. <ion-grid>
  2. <ion-row>
  3. <ion-col class="ion-align-self-start">
  4. <div>
  5. 1 of 4
  6. </div>
  7. </ion-col>
  8. <ion-col class="ion-align-self-center">
  9. <div>
  10. 2 of 4
  11. </div>
  12. </ion-col>
  13. <ion-col class="ion-align-self-end">
  14. <div>
  15. 3 of 4
  16. </div>
  17. </ion-col>
  18. <ion-col>
  19. <div>
  20. 4 of 4 <br>
  21. # <br>
  22. # <br>
  23. #
  24. </div>
  25. </ion-col>
  26. </ion-row>
  27. </ion-grid>

ClassStyle RuleDescription
.ion-align-self-startalign-self: flex-startItem is packed toward the start on the cross axis.
.ion-align-self-endalign-self: flex-endItem is packed toward the end on the cross axis.
.ion-align-self-centeralign-self: centerItem is centered along the cross axis.
.ion-align-self-baselinealign-self: baselineItem is aligned so that its baseline aligns with other item baselines.
.ion-align-self-stretchalign-self: stretchItem is stretched to fill the container.
.ion-align-self-autoalign-self: autoItem is positioned according to the parent's align-items value.

Ionic Breakpoints

Ionic uses breakpoints in media queries in order to style an application differently based on the screen size. The following breakpoint names are used in the utility classes listed above, where the class will apply when the width is met.

Breakpoint NameWidth
xs0
sm576px
md768px
lg992px
xl1200px