--- title: text-align slug: Web/CSS/text-align tags: - CSS - Propriedade CSS - Referencia - Texto CSS translation_of: Web/CSS/text-align ---
{{CSSRef}}
A propriedade CSS text-align
descreve como conteúdo inline, como texto, é alinhado no elemento pai em bloco. text-align
não controla o alinhamento de elementos em bloco, apenas o seu conteúdo inline.
{{cssinfo}}
/* Keyword values */ text-align: left; text-align: right; text-align: center; text-align: justify; text-align: justify-all; text-align: start; text-align: end; text-align: match-parent; /* Block alignment values (Non-standard syntax) */ text-align: -moz-center; text-align: -webkit-center; /* Global values */ text-align: inherit; text-align: initial; text-align: unset;
start
{{experimental_inline}}left
se a direção é esquerda-para-direita e right
se a direção é direita-para-esquerda.end
{{experimental_inline}}right
se a direção é esquerda-para-direita e left
se a direção é direita-para-esquerda.left
right
center
justify
justify-all
justify
, porém força a última linha a ser justificada.match-parent
{{experimental_inline}}inherit
, but the values start
and end
are calculated according the parent's {{cssxref("direction")}} and are replaced by the adequate left
or right
value.<p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p>
.example { text-align: left; border: solid; }
{{EmbedLiveSample("Left_alignment","100%","100%")}}
<p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p>
.example { text-align: center; border: solid; }
{{EmbedLiveSample("Centered_text","100%","100%")}}
<p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p>
.example { text-align: justify; border: solid; }
{{EmbedLiveSample("Justify","100%","100%")}}
O modo compátivel-padrão de centralizar um bloco em si sem centralizar seu conteúdo inline é setando a {{cssxref("margin")}} left e right para auto
, e.g.:
.something { margin: auto; }
.something { margin: 0 auto; }
.something { margin-left: auto; margin-right: auto; }
Especificação | Status | Comentário |
---|---|---|
{{SpecName('CSS Logical Properties', '#text-align', 'text-align')}} | {{Spec2('CSS Logical Properties')}} | Sem mudanças |
{{SpecName('CSS3 Text', '#text-align-property', 'text-align')}} | {{Spec2('CSS3 Text')}} | Added the start , end , and match-parent values. Changed the unnamed initial value to start (which it was). |
{{SpecName('CSS2.1', 'text.html#alignment-prop', 'text-align')}} | {{Spec2('CSS2.1')}} | Sem mudanças |
{{SpecName('CSS1', '#text-align', 'text-align')}} | {{Spec2('CSS1')}} | Definição iniciaç |
{{CompatibilityTable}}
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Suporte básico (left , right , center and justify ) |
1.0 | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.0")}} | 3.0 | 3.5 | 1.0 (85) |
Block alignment values {{non-standard_inline}} | 1.0{{property_prefix("-webkit")}} | {{CompatUnknown}} | {{CompatGeckoDesktop("1.0")}}{{property_prefix("-moz")}}[1] | {{CompatNo}} | {{CompatNo}} | 1.0 (85){{property_prefix("-khtml")}} 1.3 (312){{property_prefix("-webkit")}} [1] |
start {{experimental_inline}} |
1.0 | {{CompatUnknown}} | {{CompatGeckoDesktop("1.0")}} | {{CompatNo}} | {{CompatVersionUnknown}} | 3.1 (525) |
end {{experimental_inline}} |
1.0 | {{CompatUnknown}} | {{CompatGeckoDesktop("1.9.2")}} | {{CompatNo}} | {{CompatVersionUnknown}} | 3.1 (525) |
match-parent {{experimental_inline}} |
16 | {{CompatUnknown}} | {{CompatGeckoDesktop("40")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Suporte básico | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Block alignment values {{non-standard_inline}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
start {{experimental_inline}} |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
end {{experimental_inline}} |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
match-parent {{experimental_inline}} |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatGeckoMobile("40")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
true (non-standard syntax){{non-standard_inline}} |
{{CompatNo}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
[1] Both WebKit and Gecko support a prefixed version of left
, center
, and right
, that applies not only to inline content but also to block elements. This is used to implement the legacy {{htmlattrxref("align", "td")}} attributes on table elements and <center>
. Do not use these on production Web sites.