On this page (8)
Heart symbol LaTeX commands at a glance
LaTeX has one built-in heart and several more through packages. Here are the commands you’re most likely to need:
| Command | Package | Output | Mode |
|---|---|---|---|
\heartsuit |
none | ♡ outline (Computer Modern) | Math |
\varheartsuit |
newtxmath, txfonts or pxfonts |
♥ filled | Math |
\ding{170} |
pifont |
♥ filled card heart | Text |
\ding{164} |
pifont |
❤ heavy heart | Text |
\ding{163} |
pifont |
❣ heart exclamation | Text |
\ding{165} |
pifont |
❥ rotated heart | Text |
\ding{166} |
pifont |
❦ floral heart | Text |
\ding{167} |
pifont |
❧ rotated floral heart | Text |
\faHeart |
fontawesome5 |
Solid heart icon | Text |
\faHeart[regular] |
fontawesome5 |
Outline heart icon | Text |
The \ding numbers come from the Zapf Dingbats font, which the Unicode Dingbats block was largely based on. That’s why ❤ ❥ ❦ ❧ sit right next to each other in both.
\heartsuit: the built-in LaTeX heart
\heartsuit is part of standard LaTeX, so it works in any document with no packages. It’s a math-mode symbol, which means it has to sit between dollar signs in normal text:
I $\heartsuit$ \LaTeX. % works
I \heartsuit\ \LaTeX. % error: Missing $ inserted
I \ensuremath{\heartsuit} \LaTeX. % works in text or math
In Computer Modern, \heartsuit and \diamondsuit print as outlines, while \spadesuit and \clubsuit are filled. That mirrors the outline ♡ white heart suit rather than the solid ♥ heart suit, and it surprises a lot of people who expected a solid heart.
All four card suits
Here’s how the standard suit commands compare with their pifont equivalents, which are all filled:
| Suit | Math command | Computer Modern style | pifont (filled) |
|---|---|---|---|
| Spade | \spadesuit |
Filled | \ding{171} ♠ |
| Heart | \heartsuit |
Outline | \ding{170} ♥ |
| Diamond | \diamondsuit |
Outline | \ding{169} ♦ |
| Club | \clubsuit |
Filled | \ding{168} ♣ |
Which heart command should you use?
- An outline heart in a formula:
$\heartsuit$. - A filled heart in normal text:
\ding{170}with pifont. - A filled heart in a formula:
\varheartsuit, if you’re happy with newtxmath’s fonts. - A colored heart: any of the above inside
\textcolor. - An app-style icon:
\faHeartfrom fontawesome5. - Emoji-style or rare hearts: type them directly and compile with XeLaTeX or LuaLaTeX.
Filled heart in LaTeX
Option 1: pifont (recommended)
The pifont package gives you the Zapf Dingbats hearts in text mode. It works with pdfLaTeX, XeLaTeX and LuaLaTeX, and it doesn’t change any of your other fonts.
\documentclass{article}
\usepackage{pifont}
\begin{document}
Filled heart: \ding{170} \quad
Heavy heart: \ding{164} \quad
Floral heart: \ding{166}
\end{document}
Option 2: \varheartsuit
If you need a filled heart in math mode, \varheartsuit is available from newtxmath, txfonts or pxfonts. Keep in mind that these packages switch your math (and with their text companions, your body text) to a Times- or Palatino-style design, so they’re best when you want that look anyway.
\usepackage{newtxtext,newtxmath} % Times-style text and math
...
$A \varheartsuit B$
Red heart in LaTeX
Hearts take whatever color you give them. Load xcolor and wrap the symbol in \textcolor:
\usepackage{pifont}
\usepackage{xcolor}
\newcommand{\redheart}{\textcolor{red}{\ding{170}}}
I \redheart{} you. % filled red heart
\textcolor{red}{$\heartsuit$} % red outline heart
\textcolor[HTML]{E11D48}{\ding{170}} % any hex color
The empty braces after \redheart{} keep the space that follows it. To make a heart larger, use a size command like {\Huge\ding{170}}, or load graphicx and use \scalebox{3}{\ding{170}}.
Typing ♥ directly: Unicode in LaTeX
Modern LaTeX reads UTF-8 by default, but pdfLaTeX still needs to know how to print each special character. If you paste ♥ into your source and compile with pdfLaTeX, you’ll get an error like “Unicode character ♥ (U+2665) not set up for use with LaTeX.”
You have two fixes. With pdfLaTeX, map the character to a command in the preamble:
\usepackage{pifont}
\DeclareUnicodeCharacter{2665}{\ding{170}} % filled heart
\DeclareUnicodeCharacter{2661}{\ensuremath{\heartsuit}} % outline heart
With XeLaTeX or LuaLaTeX, use fontspec and any installed font that contains the hearts, such as DejaVu Sans:
% Compile with XeLaTeX or LuaLaTeX
\documentclass{article}
\usepackage{fontspec}
\newfontfamily\symbolfont{DejaVu Sans}
\begin{document}
I {\symbolfont ♥} you. Outline: {\symbolfont ♡}
\end{document}
This is also the easiest way to print rarer hearts like ☙, which have no \ding number. If you’re not sure how to type ♥ into your editor in the first place, see how to type a heart symbol. Every heart’s code point is listed in the heart Unicode reference.
Heart icons with fontawesome5
For a modern, icon-style heart, fontawesome5 works with pdfLaTeX and XeLaTeX:
\usepackage{fontawesome5}
...
\faHeart \quad \faHeart[regular] % solid and outline icons
These look like the heart buttons on websites and apps. They’re a nice fit for CVs, slides and posters. If you need the same kind of icon on a web page, the heart SVG page has ready-made code.
Hearts in tables, Beamer and Overleaf
All of the commands above work in tabular cells, Beamer slides and Overleaf projects exactly as they do in a normal document. A quick heart rating in a table might look like this:
\begin{tabular}{lc}
Recipe & Rating \\
Pancakes & \ding{170}\ding{170}\ding{170} \\
Waffles & \ding{170}\ding{170}$\heartsuit$ \\
\end{tabular}
On the web, MathJax and KaTeX understand \heartsuit and the other card suits, but not package commands like \ding. For hearts on web pages outside math, use HTML entities instead. The heart symbol HTML code guide covers those. If you write your papers on Linux, the Linux typing guide shows how to type ♥ directly for XeLaTeX projects.