Heart Symbol in LaTeX

The standard heart symbol in LaTeX is \heartsuit, used in math mode as $\heartsuit$. In the default Computer Modern font it prints an outline heart ♡. For a filled heart ♥, load pifont and write \ding{170}, or use \varheartsuit from newtxmath. Color either one with the xcolor package.

Updated

Tap a heart to copy it

7 hearts

Tap to copy · long-press or right-click for more

On this page (8)
  1. Heart symbol LaTeX commands at a glance
  2. \heartsuit: the built-in LaTeX heart
  3. Which heart command should you use?
  4. Filled heart in LaTeX
  5. Red heart in LaTeX
  6. Typing ♥ directly: Unicode in LaTeX
  7. Heart icons with fontawesome5
  8. Hearts in tables, Beamer and Overleaf

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: \faHeart from fontawesome5.
  • Emoji-style or rare hearts: type them directly and compile with XeLaTeX or LuaLaTeX.

Filled heart in LaTeX

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.

Frequently asked questions

How do I write a heart symbol in LaTeX?

Use $\heartsuit$. It needs no extra package, but it must be in math mode, so wrap it in dollar signs in running text. In the default Computer Modern font, it prints an outline heart. For a solid heart, add \usepackage{pifont} and use \ding{170}.

How do I get a filled heart in LaTeX?

The simplest way is the pifont package: \usepackage{pifont} in the preamble, then \ding{170} for ♥ or \ding{164} for ❤. If you prefer a math symbol, \varheartsuit from newtxmath (or the older txfonts and pxfonts) gives a filled heart, but those packages also change your math font.

How do I make a red heart in LaTeX?

Load xcolor and wrap the heart in \textcolor: \textcolor{red}{\ding{170}} for a filled red heart, or \textcolor{red}{$\heartsuit$} for an outline. Define a macro such as \newcommand{\redheart}{\textcolor{red}{\ding{170}}} if you use it often.

Why do I get "Unicode character ♥ not set up for use with LaTeX"?

pdfLaTeX reads UTF-8 but only knows how to print characters that have a definition. Either use a command like \ding{170} instead of typing ♥, add \DeclareUnicodeCharacter{2665}{\ding{170}} to the preamble (with pifont loaded), or compile with XeLaTeX or LuaLaTeX and a font that contains the heart.

Does \heartsuit work in MathJax, KaTeX and Overleaf?

Yes. \heartsuit is a standard TeX symbol, so it works in Overleaf, MathJax and KaTeX. Package commands such as \ding{170} work in Overleaf, where you can load packages, but not in MathJax or KaTeX, which handle math commands rather than LaTeX packages.

Related pages

Your text — tap hearts to add0