# Margins - how to set them for automatic new lines

**URL:** <https://forums.ankiweb.net/t/margins-how-to-set-them-for-automatic-new-lines/19041>\
**Category:** Help\
**Created:** [April 13, 2022, 11:06am UTC](https://forums.ankiweb.net/t/margins-how-to-set-them-for-automatic-new-lines/19041 "2022-04-13T11:06:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan100](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jonathan100/32/3143_2.png) [@jonathan100](https://forums.ankiweb.net/u/jonathan100)\
**Post date:** [April 13, 2022, 11:06am UTC](https://forums.ankiweb.net/t/margins-how-to-set-them-for-automatic-new-lines/19041/1 "2022-04-13T11:06:50Z")

</div>

Dear ladys and gentleman,  
do you know how to set left and right margins?

At the moment I have so wiede text blocks on the pc  
and when I use Enter for new lines I get a terrible layout on the smartphone.

Do you have some ideas? 🙂

Thank you so much in advance for your time  
and of course your help

Best greetings  
Jonathan

PS:  
I couldn’t find anyting in:

- adons
- overview Styling & HTML
- topics in forum

---

<div class="post-metadata">

**Author:** ![homocomputeris](https://avatars.discourse-cdn.com/v4/letter/h/bc8723/32.png) [@homocomputeris](https://forums.ankiweb.net/u/homocomputeris)\
**Post date:** [April 13, 2022, 11:37am UTC](https://forums.ankiweb.net/t/margins-how-to-set-them-for-automatic-new-lines/19041/2 "2022-04-13T11:37:14Z")

</div>

> [@jonathan100](#):
>
> At the moment I have so wiede text blocks on the pc

You can use CSS styling from this template as an example: they are supposed to wrap text after 800 px.

> <https://github.com/Ajatt-Tools/AnkiNoteTypes/tree/main/templates/Japanese%20sentences>
>
> //github.com/Ajatt-Tools/AnkiNoteTypes/tree/main/templates/Japanese%20sentences

---

<div class="post-metadata">

**Author:** ![kleinerpirat](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kleinerpirat/32/19863_2.png) [@kleinerpirat](https://forums.ankiweb.net/u/kleinerpirat)\
**Post date:** [April 13, 2022, 11:43pm UTC](https://forums.ankiweb.net/t/margins-how-to-set-them-for-automatic-new-lines/19041/3 "2022-04-13T23:43:58Z")

</div>

I strongly advise against using linebreaks without semantic meaning. Purely visual customizations should be done with CSS.

## The Basics

> [@Center-left alignment for Cloze deletion](https://forums.ankiweb.net/t/center-left-alignment-for-cloze-deletion/16799/9):
>
> here’s the HTML structure of an Anki card:
> 
> ![image](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/2X/f/fe0e4de94dc11f7f23f0b5b64576ed45f7686a0c.png)
> 
> The green is the content of the card.

Both the `body` and the `div` are HTML elements. They have identifiers by which they’re selectable in CSS:

- the `body` element has the class `card` which can be selected with a leading dot (`.card`)
  - the same class can be given to any number of elements
  - you could also use the HTML tag (`body`), but that’s a bit less specific - best would be to combine the two into a single selector: `body.card`

- the highlighted div has an id: `qa` ( **q** uestion/ **a** nswer) which would be selected with a leading hashtag (`#qa`)
  - an id should be a unique identifier for a single element, so there’s no need for `div#qa`

## Styling

Now that we know what we can style, let’s apply some CSS to solve your issue:

```auto
#qa {
  max-width: 900px; // arbitrary
}

```

#### Why not target the body?

- because we should apply size limits to the closest parent container of the text you want to restrict, which in Anki’s case is `#qa` - anything above in the HTML hierarchy would work too, but isn’t necessary and could have unwanted effects. Similar to the combined CSS-selector above, we want to be as specific as possible to achieve our goal.

---

<div class="post-metadata">

**Author:** ![jonathan100](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jonathan100/32/3143_2.png) [@jonathan100](https://forums.ankiweb.net/u/jonathan100)\
**Post date:** [April 23, 2022, 11:52am UTC](https://forums.ankiweb.net/t/margins-how-to-set-them-for-automatic-new-lines/19041/5 "2022-04-23T11:52:13Z")

</div>

.card {  
text-align: center;  
font-family: arial;  
font-size: 20px;color: black;  
background-color: white;  
}

.container {  
display: inline-block;  
text-align: left;  
max-width: 300px  
}

Got it, and btw:  
mx-width of 300px is the exact width for anki android

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 4:24am UTC](https://forums.ankiweb.net/t/margins-how-to-set-them-for-automatic-new-lines/19041/6 "2023-05-01T04:24:11Z")

</div>

Closed on May 1, 2023, 4:24am UTC


