The card layout screen allows you to control how the information you enter into Anki is presented as one or more cards. The first tab lets you control what fields appear on the front and back, and general card settings. The second tab allows you to customize fields, and how each field is displayed.

You can access the card layout by pressing the Card Layout button while editing, Edit>Card Layout while reviewing, or the the Card Layout button while editing a model.

Card Templates

clayout1.png

Card templates let you control what is shown on the front and back of a card, and options like whether you want to type in the answer.

Changing a card template changes all cards that use that template. Templates are thus useful for controlling layout you don’t want to change on each card.

The options on this page are described below.

Template

Controls the currently selected template. When you enter the card layout screen while editing a card, the template is locked to the card you were editing. If you wish to change the template a card is using, you can use Actions>Change Model in the browser.

If you enter the card layout screen when adding cards, all active templates that can be generated are shown. For information on active/inactive templates, please see the browser.

By default, Anki will only generate cards if the question half of the card contains a non-blank field. This prevents cards from being generated where the question would be blank. Please note that text you place in the template, and special fields like tags are not counted.

If you enter the card layout screen from the model properties window, all templates are shown.

Question & Answer

Please see the section below for more information.

Text you enter here will be placed on every card that uses this template.

The most basic template looks something like this:

{{Front}}

This means to take the text from the Front field, and place it in the template. Field creation is covered in the next section.

It’s always a good idea to create a separate field for each piece of information you want on a card. Imagine you want a set of cards with four pieces of information on the front: the foreign language word, a picture, an audio clip of the pronunciation, and a notes field. After creating the fields, your question area might look like:

{{Foreign Word}}
{{Audio Clip}}
{{Image}}
{{Notes}}

If you later decide that you’d prefer to have the notes on the back of the card (the answer), simply moving the notes field to the answer portion of the template will update all the cards at once. If you had instead entered all four pieces of information into a single field, it would be very difficult to change the presentation later.

There are three special fields which you can include in your template:

This fact's tags: {{Tags}}
This fact's template name: {{cardModel}}
This fact's model: {{modelTags}}

Non-field content

Your templates are not limited to a list of fields. You can also include arbitrary text on your templates. For example, if you’re studying capital cities, you might create a question like this:

What's the capital city of {{Country}}?

Templates are written in the same language used to write webpages: HTML. This affords you a lot of flexibility in the layout of your cards, but means that styling and newlines may behave differently to what you expect.

Styling non-field content

You can use standard HTML to style text in your templates. For example, the following selects Arial as the font, with a font size of 50.

<span style="font-family: arial; font-size: 50px;">
What's the capital city of {{Country}}?
</span>

If you try this out yourself, you may be surprised to find that the country is displayed in a different font or size than the rest of the text. This is because the field styling is overriding the styling we defined with the HTML. To fix this, we can tell Anki not to use any field styling, by using three curly brackets instead of two, like this:

<span style="font-family: arial; font-size: 50px;">
What's the capital city of {{{Country}}}?
</span>

You can also change the colour of the text:

<span style="color: #ff0000;">
What's the capital city of {{{Country}}}?
</span>

HTML uses colour codes to define colours. You can find a list of colours on this webpage.

There are a wealth of other styling possibilities with HTML such as images, tables, horizontal rules, and so on. Covering them all is outside the scope of this manual, but there are plenty of good introductory guides to HTML available on the web.

Newlines

When a line in the question or answer ends with a field, a newline is automatically inserted onto the card. But if a line doesn’t end with a field, no newline is inserted. If you have the following on your card template:

Line 1
Line 2

Then in the preview, you’ll actually see:

Line 1 Line 2

In HTML, you need to use a special code to start a newline: <br>. So you would change your template like so:

Line 1<br>
Line 2

Anki doesn’t add newlines automatically for non-field content, because that would interfere with more advanced formatting.

Advanced: Stripping HTML from fields

You can also use field replacement to create dictionary links. Imagine you’re studying a language and your favourite online dictionary allows you to search for text using a web URL like:

http://example.com/search?q=myword

You could add an automatic link by doing the following in your template:

{{Expression}}

<a href="http://example.com/search?q={{{Expression}}}">check in dictionary</a>

However, Anki doesn’t support mixing {{ and {{{ references to the same field within the question and answer area, and if the expression contains any HTML (because you bolded part of it, for example), then this link won’t work. Instead, Anki provides a way to strip all HTML from a field. The correct template would be:

{{Expression}}

<a href="http://example.com/search?q={{text:Expression}}">check in dictionary</a>

Advanced: Conditional Replacement

An example:

This text is always shown.

{{#FieldName}}
This text is only shown if FieldName has text in it
{{/FieldName}}

{{^FieldName}}
This text is only shown if FieldName is empty
{{/FieldName}}

A real life example is only showing a label if the field is not empty:

{{#Tags}}Tags: {{Tags}}{{/Tags}}

You can also use conditional replacement to control which cards are generated. For example, consider a template with two fields on the question:

{{Expression}}
{{Notes}}

Normally a card would be generated if either the expression or notes field had text in it. If you only wanted a card generated if expression was not empty, then you could change the template to this:

{{#Expression}}
{{Expression}}
{{Notes}}
{{/Expression}}

Advanced: Changing the delimiter for LaTeX

It’s not uncommon for {{ and }} to pop up in LaTeX code when writing mathematical equations. To ensure that your LaTeX equations don’t conflict with Anki’s field replacements, it’s possible to change the separator to something else.

For example, if you have a template:

{{latex field}}

Changing it to the following will make it unlikely that the LaTeX will conflict:

{{=<% %>=}}
<%latex field%>

Note that if you put the latex tags in the card template rather than the fields, you need to use the following syntax so that the usual field colouring is stripped. If you leave off the { in the example below, LaTeX will generate errors as HTML is being passed to it.

{{=<% %>=}}
[latex]<%{field%>[/latex]

Other Options

If you change the "don’t ask me to type in the answer" box, Anki will ask you to type in the answer, then compare what you typed with the correct answer and show you if you were correct or not. This feature does not change how the cards are answered - you still have a choice of answer buttons so you can judge for yourself how well you remembered.

If "hide the question when showing the answer" is enabled, after clicking "show answer" during reviewing, only the answer portion of the card will be shown. This is useful if the question and answer area are similar. For example, if you have an image which is partially blanked out for the question, and the full image for the answer.

The last option controls whether cards will be created if the answer area is blank. By default cards will be created even if the answer side of the card is blank.

Fields

clayout2.png

The top area allows you to add, delete and reorder fields. Changing the order of fields changes how they are displayed when adding/editing cards, but does not alter how cards appear during reviews.

You can choose separate font sizes for reviewing and editing. If you want to use different fonts for editing and reviewing, please see the section on format stripping above.

Options:

Prevent Duplicates

Won’t allow cards to be added if this field is already used by another fact in this model. If you want to find duplicates across different models, you can use the browser.

Prevent empty entries

Won’t allow cards to be added if this field is blank.

Preserve whitespace

This option controls whether spaces in the text are treated normally, or treated like HTML. Most users will want to leave the default setting; if you’re including complex HTML in your fields you may want to disable it.

Sort as numbers

When sorting by this field in the browser, using numeric sorting instead of alphabetical sorting ("1,2,3" not "1,10,2")

Reverse text direction

Enable this if you’re entering a language that displays text from right to left, such as Arabic, Hebrew, and so on.