Both EPUB and MOBI (Kindle) file formats are based on HTML, the code used to build webpages. The HTML inside the EPUB or MOBI is formatted — font family, font size, text alignment, spacing between paragraphs — with CSS (cascading style sheets), exactly the same way webpages are styled.
In fact, you might consider your e-book as a microwebsite. There’s at least one HTML or XHTML file that contains the text from your book, files for each of the images, a file for the styles, and some other files that stitch all the files together.
These other files use a standard format developed by the International Digital Publishing Forum that is based on XML (Extensible Markup Language). XML handles the different types of information a document contains: title, author, publisher, ISBN, date published, so on.
All these files — HTML, CSS, etc. — are then ZIPped up and given the EPUB file extension.