To handle dark and light modes in Theme UI, use the useColorMode hook. Toggle between default and dark modes by setting up a button with logic to switch modes using the useColorMode hook.